Skip to content
Advertisement

How can I change the “disabled icon” style using SynthLookAndFeel?

I’m currently designing a Swing app with a custom “yellow on black” Look and Feel, and it seems SynthLookAndFeel is the way to go.

All my buttons consist of an ImageIcon (no text), for example: Original

When buttons are disabled, I would like the icons to turn to a faded yellow: Desired

However, the default disabled icons are just greyscale versions of the “enabled” ones, and that breaks the yellow feel: Current

I read in this answer that disabled icons are generated internally by getDisabledIcon(), but I find no place to control it from synth’s XML file.

I also read about SynthLookAndFeel’s SynthPainter class, but it doesn’t seem to address the question of disabled icons.

Is there a way to control that “getDisabledIcon” behaviour using SynthLookAndFeel, or am I asking too much ? In the latter case, what would be the best suited look and feel to use or extend for easy definition of button backgrounds, shapes, etc ?

Any hint is welcome.

Advertisement

Answer

OK, I think I found a clean way.

I was hesitating between finding a way with SynthLookAndFeel or subclassing another L&F… But didn’t think of subclassing SynthLookAndFeel itself 🙂

I’ve now got an implementation of SynthLookAndFeel that does exactly what I want, meaning the “disabled” icon is not a greyscale one, it’s a desaturated, dimmed, color version: enter image description here

Here we go for the full code:

JavaScript

Much simpler than I thought, in the end.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement