Thursday, June 23, 2005

Themes in pluggable Look & Feel Swing

In addition to the pluggable look and feel UI Managers that Swing provides, each PLAF can also have various themes associated with it. These themes allow U to change some common properties such as 'font size', 'background color of a component' etc.

The abstract javax.swing.plaf.metal.MetalTheme class offers about fifty settings that let you customize the fonts and colors of the Swing components. By creating different subclasses, you can swap many of the properties at once when you change the look and feel.

MetalTheme theme = new MyCustomTheme();
MetalLookAndFeel.setCurrentTheme(theme);
UIManager.setLookAndFeel(new MetalLookAndFeel());

For an example of theme usage, try out the Metalworks demonstration that comes with the Java 2 SDK distribution. Simply change the current directory to the demo/jfc/Metalworks directory, and run the demonstration with the following command:

java -jar Metalworks.jar

No comments:

Post a Comment