Combo selector for selecting Substance skins

April 16th, 2009

While most applications do not benefit from changing the visual appearance (skins) at runtime, it is a valuable tool during the design phase of the project. There are two levels of visual changes for Swing applications – switching to a different look-and-feel by using the UIManager.setLookAndFeel call, or switching to a different skin in the skinnable look-and-feels.

Substance look-and-feel provides a few APIs that allow querying the available skins and changing the skins on the fly. Here is the list of steps that you need to do to add a combobox selector that shows all the available skins and changes the global Substance skin on selection change:

  • Use the getAllSkins() API to populate the combobox with the list of all available Substance skins.
  • Use the getCurrentSkin() API to select the combobox entry that matches the current Substance skin.
  • Since the model entries behind the combobox are SkinInfo objects, extend the default Substance combobox cell renderer to use the display name of the skin.
  • Finally, register an action listener on the combobox which gets triggerred on any selection change. The action listener uses the setSkin(String className) API to set the selected skin as the new global Substance skin. Note that there is no need to explicitly invoke SwingUtilities.updateComponentTree on all your windows after calling this Substance API.

The complete code is available in the CVS repository. For more information on working with Substance skins, see the updated skin documentation.

The development of the next 5.2 version of Substance (code-named Quebec) is wrapping up. You’re more than welcome to take the latest 5.2dev binary drops for a spin. The release candidate is planned for May 11, with the final release scheduled for May 25.