Java Reference
In-Depth Information
Tip The swing.installedlafs and swing.auxiliarylaf property settings are comma-separated
lists of installed look and feel classes.
You may notice that the Synth class shown in the class hierarchy in Figure 20-1 is not listed
in the default set of installed look and feel classes. Synth requires a secondary configuration
file; it isn't something you can just switch to on the fly without defining the custom appearances.
This base look and feel class provides the framework for customization. You'll learn how to use
the Synth look and feel in the “SynthLookAndFeel Class” section later in this chapter.
The WindowsClassicLookAndFeel is used when the Windows XP style is not appropriate for
the user's platform or the swing.noxp system property is set.
Customizing the Current Look and Feel
In Chapter 3, you looked at the MVC architecture as well as how the Swing components combine
the view and the controller into a UI delegate. Now, you will delve into the UI delegate for the
Swing components. Basically, if you don't like how a Swing component looks, you tell the
UIManager to change it, and then it will never again look the way it did.
UIManager Class
Whenever you need to create a Swing component, the UIManager class acts as a proxy to get
information about the currently installed look and feel. That way, if you want to install a new
look and feel or change an existing one, you don't need to tell the Swing components directly;
you just inform the UIManager .
Each discussion of components in earlier chapters has been accompanied by a table of
all the settings that can be changed through the UIManager . In addition, this topic's appendix
provides an alphabetical listing of all available settings for JDK 5.0. Once you know the property
string for the setting you want to change, you call the public Object UIManager.put(Object
key, Object value) method, which changes the property setting and returns the previous
setting (if one existed). For instance, the following line changes the background to red for
JButton components. After you put a new setting into the UIManager class lookup table, any
components created in the future will use the new value, Color.RED .
UIManager.put("Button.background", Color.RED);
Once you place new settings into the lookup table for the UIManager , the new settings will
be used when you create a new Swing component. Old components aren't automatically
updated; you must call their public void updateUI() method if you want them to be individu-
ally updated (or call updateComponentTreeUI() to update a whole window of components). If
you're creating your own components, or you're just curious about the current setting for one
of the different component properties, you can ask the UIManager with one of the methods
listed in Table 20-3.
 
Search WWH ::




Custom Search