I Used .setBackground
and .setForeground
and they didn't work, the color is like Orange, can't change it.
How to change JProgressBar color?
Asked Answered
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 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 :-) –
Chaconne @nIcE cOw there are a few www sites, but I use UIManager Defaults, because there are accesible all official L&F –
Floeter
@Floeter : Wow :-) thankx for pointing out. That's impressive and quite informative. Exactly what I was looking for, Thankyou so much :-) –
Chaconne
Shouldn't you change color only for THIS progress bar, not defaults for all progress bars in the application (like in Alex's post)? –
Backstairs
@Floeter 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 –
Claar
@madhawa priyashantha depends of NativeOS and used LookAndFeel, a.m. code lines are for metal look and feel –
Floeter
@Floeter can i use this for Nimbus look and feel also? –
Claar
@madhawa priyashantha yes but you have to override Painter for JProgressBar –
Floeter
@Floeter finally i solved my case with your guidance –
Claar
@madhawa priyashantha for excelent output to search for AbstractPainter, then is possible to create rounded corners (never used) –
Floeter
I'm still getting the same orange color! –
Mariannemariano
You should set the setStringPainted property to true:
progressBar.setStringPainted(true);
progressBar.setForeground(Color.blue);
progressBar.setString("10%");
Thanks, this is the best way to set an individual color. –
Capablanca
But that would change the text color, not the progress color. –
Garlen
Just try, it changes the foreground of the progress bar –
Chive
I guess it depends on the L&F you're using. That didn't work with Nimbus for instance. –
Garlen
Will this be the normal Java green progress bar that we are used to seeing in Eclipse? –
Heall
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
© 2022 - 2024 — McMap. All rights reserved.
UIManager
; see also this alternative. – Hesta