Java Reference
In-Depth Information
Note Nothing stops multiple look and feel classes from rendering to the screen for the same component.
It's the responsibility of the auxiliary look and feel creator to take care not to compete with the primary look
and feel when rendering to the screen.
SynthLookAndFeel Class
The Synth look and feel is a full-fledged look and feel, not just a themed extension to Metal,
Windows, or Motif. Instead of working with a UIResource table though, the class starts with a
blank canvas and gets its entire definition from a single XML file.
Configuring Synth
The configuration of the Synth look and feel might go something like this:
SynthLookAndFeel synth = new SynthLookAndFeel();
Class aClass = SynthSample.class;
InputStream is = aClass.getResourceAsStream("config.xml");
synth.load(is, aClass);
UIManager.setLookAndFeel(synth);
And what exactly goes into the configuration file, config.xml here? In your configuration
file, you specify how you want the specific components used in your program to appear. This
is commonly called skinning your application , or creating a custom skin. By simply modifying
an XML file, the entire appearance of your program changes; no programming is required.
The DTD is available from http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/
plaf/synth/doc-files/synth.dtd . The file format is fully described in http://java.sun.com/
j2se/1.5.0/docs/api/javax/swing/plaf/synth/doc-files/synthFileFormat.html . The parser
does not validate, so until tools are available to help automate the process, you'll need to use
care in creating the XML file.
There are many configuration options available with Synth, but the basic XML concept is
to define a style and bind it to a component. The <style> tag allows you to customize proper-
ties like the font, colors, insets, and background or border image.
To demonstrate, Listing 20-11 defines a custom style named button . Normally, the text
will appear in bold 24-point, Monospaced font. When the mouse moves over the associated
control, the font changes to a 48-point italic SansSerif font, and the background color changes
to blue. When the component is pressed, the font changes again, this time to a 36-point bold-
italic Serif font, and the background becomes red. The final part of the configuration file asso-
ciates the style named button with the JButton control, via the <bind> tag.
 
Search WWH ::




Custom Search