Substance client properties

View all API methods.

View all client properties.


Client property name

SubstanceLookAndFeel.THEME_PROPERTY

Description

Property name for setting theme. This property is used both as a JVM flag and as a client property that can be set on a specific component.

If this property is used as a JVM flag, the value should be a fully-qualified name of the theme class. This class must have a default (no-argument) constructor. This means that you can not specify "generic" themes such as SubstanceMixTheme or SubstanceToneTheme.

If this property is used as a client property, the value can be one of:

  • String - theme display name (only for primitive themes).
  • ThemeInfo object (call SubstanceLookAndFeel.getAllThemes()).
  • SubstanceTheme object itself.

See also


Sample code

import java.awt.FlowLayout;

import javax.swing.*;

import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.theme.SubstanceBrownTheme;

/**
 * Test application that shows the use of the
 {@link SubstanceLookAndFeel#THEME_PROPERTY} client property.
 
 @author Kirill Grouchnikov
 @see SubstanceLookAndFeel#THEME_PROPERTY
 */
public class ThemeProperty extends JFrame {
  /**
   * Creates the main frame for <code>this</code> sample.
   */
  public ThemeProperty() {
    super("Mouse over buttons to see themes");

    this.setLayout(new FlowLayout());

    JButton buttonDefault = new JButton("default");

    JButton buttonByName = new JButton("by name");
    // mark button to have custom theme based on the theme display name
    buttonByName.putClientProperty(SubstanceLookAndFeel.THEME_PROPERTY,
        "Bottle Green");

    // mark button to have custom theme based on the theme info
    JButton buttonByInfo = new JButton("by info");
    buttonByInfo.putClientProperty(SubstanceLookAndFeel.THEME_PROPERTY,
        SubstanceLookAndFeel.getAllThemes().get("Barby Pink"));

    // mark button to have custom theme based on the theme instance
    JButton buttonByObject = new JButton("by object");
    buttonByObject.putClientProperty(SubstanceLookAndFeel.THEME_PROPERTY,
        new SubstanceBrownTheme());

    this.add(buttonDefault);
    this.add(buttonByName);
    this.add(buttonByInfo);
    this.add(buttonByObject);

    this.setSize(400200);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  /**
   * The main method for <code>this</code> sample. The arguments are
   * ignored.
   
   @param args
   *            Ignored.
   @throws Exception
   *             If some exception occured. Note that there is no special
   *             treatment of exception conditions in <code>this</code>
   *             sample code.
   */
  public static void main(String[] argsthrows Exception {
    UIManager.setLookAndFeel(new SubstanceLookAndFeel());
    JFrame.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        new ThemeProperty().setVisible(true);
      }
    });
  }
}

The screenshot below shows application frame with second button marked with custom theme. The value of this property is String - theme display name. The mouse hovers over the button to show the active color (the global theme is Aqua).

The screenshot below shows application frame with third button marked with custom theme. The value of this property is ThemeInfo object (taken from call to SubstanceLookAndFeel.getAllThemes()). The mouse hovers over the button to show the active color (the global theme is Aqua).

The screenshot below shows application frame with fourth button marked with custom theme. The value of this property is SubstanceTheme object. The mouse hovers over the button to show the active color (the global theme is Aqua).