I Used .setBackground
and .setForeground
and they didn't work, the color is like Orange, can't change it.
Asked
Active
Viewed 5.3k times
18

Matthieu
- 2,736
- 4
- 57
- 87

Ali Bassam
- 9,691
- 23
- 67
- 117
3 Answers
24
I think that these values are right for you
UIManager.put("ProgressBar.background", Color.ORANGE);
UIManager.put("ProgressBar.foreground", Color.BLUE);
UIManager.put("ProgressBar.selectionBackground", Color.RED);
UIManager.put("ProgressBar.selectionForeground", Color.GREEN);
-
+1 for `UIManager`; see also this [alternative](http://stackoverflow.com/a/8886795/230513). – trashgod May 27 '12 at 13:57
-
+1 for this answer, but i wonder how to know the `value of the Key`, how will I know `UIManager.put(ProgressBar.whatElseCanIWriteHere, myValue)` , is there any Doc, which discusses this part, If there is one, please point me at it, I be highly Thankful :-) – nIcE cOw May 28 '12 at 02:45
-
@nIcE cOw there are a few www sites, but I use [UIManager Defaults](http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/), because there are accesible all official L&F – mKorbel May 28 '12 at 06:19
-
@mKorbel : Wow :-) thankx for pointing out. That's impressive and quite informative. Exactly what I was looking for, Thankyou so much :-) – nIcE cOw May 28 '12 at 06:31
-
2Shouldn't you change color only for THIS progress bar, not defaults for all progress bars in the application (like in Alex's post)? – Lukasz Czerwinski Sep 14 '13 at 14:37
-
@mKorbel if i'm using netbean ,where should i put this code.i put them in constructor ,but still progress_bar is ugly default orange color – Madhawa Priyashantha Aug 05 '14 at 06:43
-
@madhawa priyashantha depends of NativeOS and used LookAndFeel, a.m. code lines are for metal look and feel – mKorbel Aug 05 '14 at 07:09
-
@mKorbel can i use this for Nimbus look and feel also? – Madhawa Priyashantha Aug 05 '14 at 07:13
-
2@madhawa priyashantha yes but you have to override [Painter for JProgressBar](http://stackoverflow.com/search?q=user%3A714968+%5Bjprogressbar%5D+nimbus) – mKorbel Aug 05 '14 at 07:30
-
@mKorbel finally i solved my case with your guidance – Madhawa Priyashantha Aug 05 '14 at 08:18
-
1@madhawa priyashantha for excelent output to search for AbstractPainter, then is possible to create rounded corners (never used) – mKorbel Aug 05 '14 at 09:04
-
1I'm still getting the same orange color! – Jay Patel Nov 22 '18 at 05:28
20
You should set the setStringPainted property to true:
progressBar.setStringPainted(true);
progressBar.setForeground(Color.blue);
progressBar.setString("10%");

Alexey
- 7,127
- 9
- 57
- 94
-
1
-
2
-
1
-
8I guess it depends on the L&F you're using. That didn't work with Nimbus for instance. – Matthieu Jun 28 '13 at 10:27
-
Will this be the normal Java green progress bar that we are used to seeing in Eclipse? – Doug Hauf Feb 04 '14 at 14:07
0
You can use this:
UIManager.put( "nimbusOrange", new Color( 38, 139, 210 ) );
It's works for me, only change the color, you can use Color.RED or similar

Roel Leal
- 49
- 2