bulenkov/iconloader

Icons in disbled JButtons

mrieser opened this issue · 3 comments

If I add an ImageIcon (not loaded using IconLoader) to a JButton, and then call setEnabled(false) on that button, the icon is displayed as a gray mask only. If I add an Icon loaded using IconLoader to a JButton, the Icon is always shown in full color, no matter of the state of the button.

Is there any way go get IconLoader's Icon also to display as gray mask (or somehow dimmed/different) on disabled JButtons?

Thanks for the report. Looks like It's IconLoader bug. I'll take a look.

I was just digging around the code a bit, and am not sure there can be done much about it:
AbstractButton allows to set different icons for the different states. If no disabledIcon is set, it will try to generate one in AbstractButton.getDisabledIcon(). In this method, it calls UIManager.getLookAndFeel().getDisabledIcon(this, getIcon());. And LookAndFeel.getDisabledIcon() has a simple if (icon instanceof ImageIcon) { ... } return null. So as long as IconLoaders Icons don't inherit from ImageIcon (which I guess will not work that easily for other, retina-obvious reasons), I guess swing just doesn't support it and we need to manually set a custom disabled icon. (Java 7u67 used for looking into this).

Now it would be cool if iconloader could automatically generate such an icon given an existing icon ;-) But for that I should probably open a new issue? Feel free to close this one as "won't fix" if my analysis of the problem is correct.

EDIT: just found out there is already a method IconLoader.getDisabledIcon() -- so I'm happy :-)

We can check that we're inside disabled container/component in paintIcon(...) method.
Now it works. Thank you. http://screencast.com/t/DXZ49s4qm