1

My boss has put me in charge of building a production dashboard to track the efficiency of the workers on a production line. He wants a progress bar to fill up in relation to the time and change colors if the worker is running on time or if they're behind, etc. I need to know if you can have multiple colors for one JProgressBar that changes as the bar fills up to show those changes. I'm referring to

something like this.

Is this even possible? If not, what's my best course of action to go about doing this? I've thought about putting multiple JProgressBars together and doing some calculations to find out which section needs to be which color, unless there's a better way to go about it.

Matthew Brzezinski
  • 1,685
  • 4
  • 29
  • 53
BamSquid
  • 35
  • 1
  • 2
  • 6
  • Why not just use one progress bar and use a single color like: `{Green, Red}` for `{On-Time, Behind}`? – Matthew Brzezinski Nov 18 '16 at 17:46
  • https://stackoverflow.com/questions/28908135/how-to-customize-a-jprogressbar This should be a helpful start. – Matthew Brzezinski Nov 18 '16 at 17:47
  • That's how I'm doing it now, but that's not the way he wants it done. He wants to be able to look at it and see where they fell behind and where they caught back up, like what I showed in the picture, not just one color for whether they are currently on time or not. – BamSquid Nov 18 '16 at 17:51
  • Looking at the link I posted above, you might be able to create multiple progressbars, setting the width of them to something predetermined (length of a task), placing them side-by-side, then setting those colors for each piece individually. Looking around I don't see anything for setting colors to from `n to m` to a certain value. – Matthew Brzezinski Nov 18 '16 at 17:57
  • I had a feeling that's what I was going to have to do, but I was really hoping there was a different way. Thanks for your help! If no one else has any other suggestions, do you mind posting your comment as an answer and I'll pick it? – BamSquid Nov 18 '16 at 18:11
  • An alternative would be to create your own Swing component from a JPanel. You could pass a List of Segment objects. Each Segment object would have a from value, a to value, and an Enum that would meaningfully indicate green, yellow, or red. The from and to values would run from zero to 100. – Gilbert Le Blanc Nov 18 '16 at 23:20

2 Answers2

0

Looking at the link I posted above, you might be able to create multiple progressbars, setting the width of them to something predetermined (length of a task), placing them side-by-side, then setting those colors for each piece individually. Looking around I don't see anything for setting colors to from n to m to a certain value.

Matthew Brzezinski
  • 1,685
  • 4
  • 29
  • 53
0

Make a progress bar whose foreground colour is "transparent". Put a graphic behind it with all the colours you want. As the progress bar fills up, the transparent part of it will expose the graphic behind it.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110