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(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.
* @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[] args) throws 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 ).
|