0

All, I am using java swing's UIManager to set this theme

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

This theme is terrible at differentiating disabled/enabled backgrounds for buttons, so I've been battling trying to get this to change the disabled background. Nothing is working for me. I don't understand what I'm doing wrong, below are all my approaches so far

//My color constant
Color disabledButton = new Color(255,124,124);

//Maybe its these?
UIManager.put("Button.background", disabledButton);
UIManager.put("Button.foreground", disabledButton);

//No maybe this...
UIManager.put("Button.disabled", disabledButton);

//Okay how about this
UIManager.put("Button.disabled", "DerivedColor(color=255,124,124 parent=control offsets=0.0,0.0,0.0,0 pColor=255,124,124");

//NO!!?!?! WELL FINE ILL SET THE BACKGROUND MYSELF
myButton.setBackground(disabledButton);

None of these work... where am I making an error?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Constantin
  • 16,812
  • 9
  • 34
  • 52
  • _Why does UIManager suck?_ Most likely because you don't use it right. Yet, with so little code provided, it's pretty much impossible to tell what's wrong. Consider posting an MVCE – Guillaume Polet Sep 17 '14 at 19:34
  • @GuillaumePolet Sure, adjusted my language. What other code would be helpful to explain a simple background change? What is an MVCE? Thanks. – Constantin Sep 17 '14 at 19:38
  • 2
    [Minimal, Verifiable, Complete Example](http://stackoverflow.com/help/mcve) – Guillaume Polet Sep 17 '14 at 19:39
  • For info, Nimbus works in a quite different way compared to other default L&F provided by JRE. Try this to see what happens: `UIManager.put("nimbusBlueGrey",Color.RED);` See also this: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/_nimbusDefaults.html#primary – Guillaume Polet Sep 17 '14 at 19:55
  • Thank you! @GuillaumePolet This is what I've been looking for. I thought it would be in the UIManager or UIDefault sections or even the JButton sections... Didn't realize there was an entire Nimbus section. – Constantin Sep 17 '14 at 20:00
  • Okay the only problem now is, I think I need to adjust `Button[Disabled].backgroundPainter` however that's a painter. This implies to me that I have to write my own painter and pass it in as opposed to adjusting a color inside the existing painter using `UIManager.get("Button[Disabled].backgroundPainter")`. Am I making this too complex? Is there another approach? – Constantin Sep 17 '14 at 20:16
  • You may take a look at this one too: http://stackoverflow.com/questions/5840599/jbutton-background-on-nimbus-laf – Guillaume Polet Sep 17 '14 at 21:10
  • See also this alternate [approach](http://stackoverflow.com/a/3420431/230513). – trashgod Sep 17 '14 at 22:14
  • 1
    @Constantin, `Didn't realize there was an entire Nimbus section.` - check out [UIManager Defaults](http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/) and change the Look and Feel to Nimbus. The "System Colors" and "Miscellaneous" items contain the base colors used by Nimbus. – camickr Sep 17 '14 at 22:24

0 Answers0