Substance look and feel - documentation
Author: substance.dev.java.net
Description: Substance look and feel
Keywords: java, look, feel, skins, plaf, swing, ui, pluggable, substance

# Substance API

View all API methods.

View all client properties.

API method | `public static void registerSkinChangeListener( SkinChangeListener skinChangeListener)`
Description | Registers a new listener on skin change. Parameters: `skinChangeListener` - New listener on skin change.
See also | setSkin(String) API. setSkin(SubstanceSkin) API. unregisterSkinChangeListener(SkinChangeListener) API.
Sample code | `import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.util.Vector; import javax.swing.*; import org.jvnet.substance.SubstanceLookAndFeel; import org.jvnet.substance.skin.*; /** * Test application that shows the use of the * {@link SubstanceLookAndFeel#registerSkinChangeListener(SkinChangeListener)} * API. * * @author Kirill Grouchnikov * @see SubstanceLookAndFeel#registerSkinChangeListener(SkinChangeListener) */ public class RegisterSkinChangeListener extends JFrame { /** * Creates the main frame for <code>this</code> sample. */ public RegisterSkinChangeListener() { super("Register skin change listener"); this.setLayout(new BorderLayout()); JPanel panel = new JPanel(new FlowLayout()); // Get all skin display names and set the vector as a model // for combobox. final JComboBox cb = new JComboBox(new Vector<String>( SubstanceLookAndFeel.getAllSkins().keySet())); cb.setSelectedIndex(-1); cb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent evt) { // Get the affected item final Object item = evt.getItem(); if (evt.getStateChange() == ItemEvent.SELECTED) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { // Get the skin info object based on // the selected skin display name SkinInfo skinInfo = SubstanceLookAndFeel .getAllSkins().get(item); // Set the global skin based on the // skin class name. SubstanceLookAndFeel.setSkin(skinInfo .getClassName()); SwingUtilities .updateComponentTreeUI(RegisterSkinChangeListener.this); } catch (Exception exc) { } }; }); } } }); panel.add(new JLabel("All skins:")); panel.add(cb); this.add(panel, BorderLayout.CENTER); // register listener SubstanceLookAndFeel .registerSkinChangeListener(new SkinChangeListener() { public void skinChanged() { // show dialog with skin changed message. SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog( RegisterSkinChangeListener.this, "Skin changed"); } }); } }); this.setSize(400, 200); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } /** * The main method for <code>this</code> sample. The arguments are ignored. * * @param args * Ignored. */ public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); SwingUtilities.invokeLater(new Runnable() { public void run() { SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin()); new RegisterSkinChangeListener().setVisible(true); } }); } }` The screenshot below shows an option pane that pops up from the registered skin listener. Note that the dialog is skinned with the new skin (Business):