Accessing look and feel default icons?

Jay R. picture Jay R. · Nov 2, 2009 · Viewed 7k times · Source

I want to change the selected icon for a JCheckbox to a different icon, let's say for example the disabled selected icon for a JCheckbox. How can I get the disabled selected icon from the UIManager?

I tried UIManager.getIcon("CheckBoxUI.disabledSelectedIcon"); Is that the wrong icon property name or is that just the wrong way to get to that resource?

Answer

Jay R. picture Jay R. · Nov 2, 2009

Apparently there isn't one by default. At least, not when I'm trying to call it.

Just dumping the keys from UIManager.getLookAndFeelDefaults().keys() produces the following if the key contains CheckBox:

CheckBox.foreground
CheckBox.border
CheckBox.totalInsets
CheckBox.background
CheckBox.disabledText
CheckBox.margin
CheckBox.rollover
CheckBox.font
CheckBox.gradient
CheckBox.focus
CheckBox.icon
CheckBox.focusInputMap

After reading akf's answer, I started digging through the UIManager code in the plaf.synth packages and found calls that essentially delegate the null disableCheckedIcon to the look and feel classes to try to convert the standard .icon to a grayed version. So I ended up with this:

Icon checkedIcon = UIManager.getIcon("CheckBox.icon");
Icon dsiabledCheckedIcon = 
   UIManager.getLookAndFeel().
      getDisabledSelectedIcon(new JCheckBox(), checkedIcon);