Java Reference
In-Depth Information
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JLabel label = (JLabel)UIManager.get(LABEL_FACTORY);
panel.add(label);
panel.revalidate();
}
};
button.addActionListener(actionListener);
frame.add(panel, BorderLayout.CENTER);
frame.add(button, BorderLayout.SOUTH);
frame.setSize(200, 200);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Note There is a special lazy class for creating an InputMap lazily: the UIDefaults.LazyInputMap
class.
Using Client Properties
If changing all the UIResource properties known to the UIManager still doesn't give you the look
and feel you desire, some of the UI delegate classes can provide their own customized capabilities
that are hidden from API views. These customized capabilities are provided as client properties
and are accessible from two JComponent methods: public final Object getClientProperty(Object
key) and public final void putClientProperty(Object key, Object value) . Keep in mind
that the key and value here are of type Object . While typically the key will be a String and the
value an object of any type, the key can also be an object of any type.
Client properties tend to be attributes of the component that are specific to the look and
feel. Instead of subclassing the look and feel delegate to expose a property through a pair of
getter/setter methods, the get/put client property methods provide access to a private instance-
level lookup table to store a new property setting. In addition, as when making changes to the
UIDefaults , modifying the client properties of a component notifies any registered property
change listeners of the component.
Most of the specific client properties have already been discussed throughout this topic
with their respective components. Table 20-7 provides a single resource for finding all the
configurable client properties. The left column shows the class the property is used in, excluding
the package name. The middle column shows the property name, which can include both the
raw text string and any class constants that are available. The right column contains the class
type to store with the property name. If the class type is a String , a list of valid values is provided,
if appropriate.
 
Search WWH ::




Custom Search