4

I'm trying to change the color of a single JProgressBar in Nimbus LAF (Look And Feel). This solution does work, but it changes the colors of ALL JProgressBars :/

    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    defaults.put("nimbusOrange",defaults.get("nimbusBase"));

In this thread is another solution to change the color for each JProgressBar individually:

    progress = new JProgressBar();
    UIDefaults defaults = new UIDefaults();
    defaults.put("ProgressBar[Enabled].backgroundPainter", new MyPainter());
    progress.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    progress.putClientProperty("Nimbus.Overrides", defaults);

Unfortunately I can't get it to work. I don't know where to find the libary for "MyPainter()". So I tried replacing this method (without knowing what I'm doing) with "defaults.get("nimbusBase")" and "Color.red". Didn't work either.

Community
  • 1
  • 1
user1430180
  • 43
  • 1
  • 3

1 Answers1

4

1.can you please to indicate which one from

UIManager.put("ProgressBar.background", Color.orange);
UIManager.put("ProgressBar.foreground", Color.blue);
UIManager.put("ProgressBar.selectionBackground", Color.red);
UIManager.put("ProgressBar.selectionForeground", Color.green);

notice valid UIDefaults for MetalLookAndFeel,

2.then please to search equivalent in Nimbus Defaults

3.then to try override the JProgressBar with logics and with this Painter

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • +1, still many a things I have to learn from the Link you gave me once regarding this thingy. I didn't knew it's that simple :-) – nIcE cOw Jun 01 '12 at 14:01
  • that could be terrible, till moment, when you know where to use standard Color (XxxRenderer), when putNimbusColor (non-compond) JComponents and for Compoun & JButtons JComponents... – mKorbel Jun 01 '12 at 14:19
  • Thank you for your quick and helpful reply. Everything works now for me. :D For any future readers: If your compiler is missing "com.sun.java.swing.Painter.class" and/or "javax.swing.Painter.class" you can [download](http://www.java2s.com/Code/JarDownload/org-netbeans-swing/org-netbeans-swing-tabcontrol.jar.zip) it here: http://www.java2s.com/Code/Jar/o/Downloadorgnetbeansswingtabcontroljar.htm – user1430180 Jun 01 '12 at 14:39
  • @Matthieu not sure if I understand correctly, in linked post is used FillPainter, which only fill available rectangle with one color, for nicer look is there required to use GradientPaint in Painter – mKorbel Jun 28 '13 at 09:46
  • 1
    @mKorbel, sorry, I got confused with my too-many search on the subject with the too-many different answers. It's clearer with your post, hvala! :) – Matthieu Jun 28 '13 at 10:20