3

Is it possible to change progress bar color using the paint listner?

I don't want just an inital foreground and a background color, but want it to work just like how a normal green color progress bar works on Windows but with my own foreground and background.

I tried the below code but it won't work

GC gc = event.gc;
Device device=Display.getDefault();
Color foreground = gc.getForeground();
Color background = gc.getBackground();
gc.setForeground(device.getSystemColor(SWT.COLOR_RED));
gc.setBackground(device.getSystemColor(SWT.COLOR_YELLOW));

Am stuck with this requirement and have been told that it's possible using the paint listener, wondering how !

Any help would be appreciated.

Abbas
  • 3,144
  • 2
  • 25
  • 45
  • possible duplicate of [SWT- How to change ProgressBar color in Windows?](http://stackoverflow.com/questions/4674678/swt-how-to-change-progressbar-color-in-windows) – Baz Apr 26 '14 at 11:18
  • 1
    So there is no way of changing the appearance of the progress bar if you don't want to paint it yourself *completely*. If you are really desperate, you could use a `JProgressBar` using the SWT/AWT bridge. – Baz Apr 26 '14 at 11:20
  • 1
    If you're just using windows (vista or above), you can use the different styles of the `ProgressBar` (red, green, yellow) as can be seen [here](http://www.eclipse.org/swt/R3_4/images/progress-bar.png). – Baz Apr 26 '14 at 13:10
  • Thanks Baz.I am aware of those state based colors, my application is intended to run on cross platforms and needs to have white/grey combination of foreground/background colors. Why can't we use the same code which is responsible to change the colors to RED,GREEN,YELLOW based on the states, to some color of our choice? If that hack is possible. Let me know your opinion. Thanks – Abbas Apr 26 '14 at 14:43
  • You can't use that mechanism because these three colors are the only ones that are defined by the OS. – Baz Apr 26 '14 at 15:01
  • @Baz I'm surprised you didn't consider this to be worthy of being an answer, Baz. It may not be what the OP wants to hear, but it's the 100% complete truth, and is a full answer. Sometimes, the truth is, "It's impossible." – Southpaw Hare Apr 28 '14 at 15:00
  • Too bad, that also means there will never be the equivalent of the famous NyanProgressBar plugin in Eclipse! – Pyves Sep 03 '19 at 19:58

1 Answers1

2

The color of progress bars are determined by the operating system.

Under most conditions in Windows environments, the progress bar will be green. Using the setState(int state) command will change the "state" of the progress bar, which under some systems will also change the color - in Windows 7, paused results in yellow and error results in red. These statuses have other meaningful connotations, however, and it could be confusing to a user to use them simply for the stylistic reasoning of color. In the general sense, you should consider the color unchangable.

Southpaw Hare
  • 1,535
  • 3
  • 24
  • 50