Java Reference
In-Depth Information
Default Synth Properties
The configuration file isn't limited to just styles and bindings. In fact, if you truly do want to
set a UIResource property, you still can, but only a limited subset is available. The file located
at http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/plaf/synth/doc-files/
componentProperties.html specifies the full set. It is much smaller than the list you'll find
in this topic's appendix. These settings are configured with either a <property> tag or a
<defaultProperty> tag. Defaults end up in the UIDefaults table for the look and feel; properties
are just that—settings for the specific control. Tags similar to the following would be placed
within a specific <style> tag to be configured:
<property key="ScrollPane.viewportBorderInsets" type="insets" value="5 5 5 5"/>
or
<object class="javax.swing.plaf.ColorUIResource" id="color">
<int>255</int>
<int>0</int>
<int>0</int>
</object>
<defaultsProperty key="Table.focusCellForeground" type="idref" value="color"/>
Working with Synth Images
Indirectly, using the SynthPainter class, you can provide images that can be used for borders
around components. However, the image must be specially created, as the painter doesn't just
draw the image. That one image must be used for components of all sizes, of that type, such as
for all text fields. The painter shares the image across different-sized controls by breaking the
component into multiple regions. The four corners are always drawn as is. The middle regions
are stretched vertically and horizontally.
Figure 20-11 shows a possible border image to use. Notice how there are curves around the
corners, but the middle areas don't have curves. The curves stay fixed when the border is
stretched.
Figure 20-11. Text component border
To use the image in Figure 20-11 within your configuration file, you need to use the
<imagePainter> tag and specify an appropriate method attribute. These map directly to the
paint XXX (SynthContext context, Graphics g, int x, int y, int w, int h, int orientation)
methods of the SynthPainter class. Since this image will be used for painting the text field
border, the method attribute should be set to textFieldBorder . You also need to specify the path
to the image (its file name and path relative to the location specified as the second argument to
the SynthLookAndFeel.load() method). Insets and colors are the other items you need to specify.
Here's the full style definition for just such a usage.
 
Search WWH ::




Custom Search