Java Reference
In-Depth Information
Whenever you create a component, the component automatically asks the UIManager to
look in the UIDefaults table for the current settings for that component. Most color- and font-
related component settings, as well as some others not related to colors and fonts, are configurable.
If you don't like a particular setting, you can simply change it by updating the appropriate entry
in the UIDefaults lookup table.
Note All predefined resource settings in the UIDefaults table implement the UIResource interface,
which allows the components to monitor which settings have been customized just by looking for those
settings that don't implement the interface.
First, you need to know the name of the UIDefaults setting you want to change. You can
find the setting names in Appendix A of this topic, which contains a complete alphabetical
listing of all known settings for the predefined look and feel types in J2SE 5.0. (These differ a
little from release to release.) In addition, included with the description of each component is
a table containing the UIResource -related property elements. (To find the specific component
section in the topic, consult the table of contents or the index.)
Once you know the name of a setting, you can store a new setting with the public static
void put(Object key, Object value) method of UIManager , where key is the key string. For
instance, the following code will change the default background color of newly created buttons
to black and the foreground color to red:
UIManager.put("Button.background", Color.BLACK);
UIManager.put("Button.foreground", Color.RED);
Fetching UIResource Properties
If you're creating your own components, or just need to find out the current value setting, you
can ask the UIManager . Although the public static Object get(Object key) method is the
most generic, it requires you to cast the return value to the appropriate class type. Alternatively, you
could use one of the more specific get XXX () methods, which does the casting for you, to return
the appropriate type:
public static boolean getBoolean(Object key)
public static Border getBorder(Object key)
public static Color getColor(Object key)
public static Dimension getDimension(Object key)
public static Font getFont(Object key)
public static Icon getIcon(Object key)
public static Insets getInsets(Object key)
public static int getInt(Object key)
public static String getString(Object key)
public static ComponentUI getUI(JComponent target)
There is a second set of overloaded methods that accept a second argument for the Locale .
 
Search WWH ::




Custom Search