Tuesday, October 10, 2006

Iconic Inversion

Here's a problem and solution described in an applet.






The goal here is to make the icon look consistent with the selected text, which means using the JList's selection fg/bg colors where the icon uses the component's normal fg/bg colors.

This applet uses a SelectionIcon, which applies a custom composite to the original icon. The custom composite looks for the list fg/bg colors in the original icon (and some colors "nearby"), and swaps them out for the selection fg/bg. It also applies a slight tint based on the selection background.

The SelectionIcon can be applied to any existing icon. It's useful for selections because you don't know a priori what your selection colors are, so it's hard to make a dedicated selection version of your original icons that will look good in all cases. Assuming that the selection fg/bg are set reasonably, your icon will look at least as good as the selection text. The high contrast colors in the above example are from Win2k, but you never know what the user may have set.

Source

4 comments:

Anonymous said...

hi, SelectionIcon.java is missing in the jar.

Anthony said...

This looks bad on Mac OS X, see image link:
picture of applet on Mac OS X

technomage said...

Yes, it does look bad on Mac OSX due to bugs in Apple's compositing code. This is fixed in their 1.6 VM; you should report it to Apple as a bug to increase its chances of being fixed in a 1.5 update.

technomage said...

The jar file has been updated to include the missing source.