Java Reference
In-Depth Information
■
Note
You can also work with the
UIDefaults
directly, by calling the
public static UIDefaults
getDefaults()
method of
UIManager
.
Client Properties
In addition to the
UIManager
maintaining a table of key/value pair settings, each instance of
every component can manage its own set of key/value pairs. This is useful for maintaining
aspects of a component that may be specific to a particular look and feel, or for maintaining
data associated with a component without requiring the definition of new classes or methods
to store such data.
public final void putClientProperty(Object key, Object value)
public final Object getClientProperty(Object key)
■
Note
Calling
putClientProperty()
with a value of
null
causes the key to be removed from the client
property table.
For instance, the
JTree
class has a property with the Metal look and feel for configuring the
line style for connecting or displaying nodes within a
JTree
. Because the setting is specific to
one look and feel, it doesn't make sense to add something to the tree API. Instead, you set the
property by calling the following on a particular tree instance:
tree.putClientProperty("JTree.lineStyle", "None")
Then, when the look and feel is the default Metal, lines will connect the nodes of the tree.
If another look and feel is installed, the client property will be ignored. Figure 4-2 shows a tree
with and without lines.
Figure 4-2.
A JTree, with and without angled lines