UIManager manages the current look and feel, the set of
available look and feels, PropertyChangeListeners that
are notified when the look and feel changes, look and feel defaults, and
convenience methods for obtaining various default values.
LookAndFeel and passing
it to setLookAndFeel. The following example illustrates
setting the look and feel to the system look and feel:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());The following example illustrates setting the look and feel based on class name:
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
Once the look and feel has been changed it is imperative to invoke
updateUI on all JComponents. The method SwingUtilities#updateComponentTreeUI makes it easy to apply updateUI to a containment hierarchy. Refer to it for
details. The exact behavior of not invoking updateUI after changing the look and feel is
unspecified. It is very possible to receive unexpected exceptions,
painting problems, or worse.
swing.defaultlaf is
non-null, use its value as the default look and feel class
name.
java.util.Properties file swing.properties
exists and contains the key swing.defaultlaf,
use its value as the default look and feel class name. The location
that is checked for swing.properties may vary depending
upon the implementation of the Java platform. Typically the
swing.properties file is located in the conf
subdirectory of the Java installation directory.
Refer to the release notes of the implementation being used for
further details.
UIManager manages three sets of UIDefaults. In order, they
are:
setLookAndFeel() is invoked). The
look and feel defaults can be obtained using the getLookAndFeelDefaults() method.
get methods
results in checking each of the defaults, in order, returning
the first non-null value. For example, invoking
UIManager.getString("Table.foreground") results in first
checking developer defaults. If the developer defaults contain
a value for "Table.foreground" it is returned, otherwise
the look and feel defaults are checked, followed by the system defaults.
It's important to note that getDefaults returns a custom
instance of UIDefaults with this resolution logic built into it.
For example, UIManager.getDefaults().getString("Table.foreground")
is equivalent to UIManager.getString("Table.foreground"). Both
resolve using the algorithm just described. In many places the
documentation uses the word defaults to refer to the custom instance
of UIDefaults with the resolution logic as previously described.
When the look and feel is changed, UIManager alters only the
look and feel defaults; the developer and system defaults are not
altered by the UIManager in any way.
The set of defaults a particular look and feel supports is defined
and documented by that look and feel. In addition, each look and
feel, or ComponentUI provided by a look and feel, may
access the defaults at different times in their life cycle. Some
look and feels may aggressively look up defaults, so that changing a
default may not have an effect after installing the look and feel.
Other look and feels may lazily access defaults so that a change to
the defaults may effect an existing look and feel. Finally, other look
and feels might not configure themselves from the defaults table in
any way. None-the-less it is usually the case that a look and feel
expects certain defaults, so that in general
a ComponentUI provided by one look and feel will not
work with another look and feel.
A System Look And Feel is intended to implement the native Look and Feel of the desktop.
There is no requirement for the standard Java Look And Feel to be the default, therefore the System Look and Feel may be the default.
A desktop may not have a consistent Look and Feel, for example if there are multiple platform-native toolkits provided to create applications for the desktop. Swing may elect any one of these to be its native Look and Feel.
Installation of the native Look and Feel may depend on platform resources being available. In the event that required resources are not available, Swing may be unable to install the System Look and Feel.
Swing's emulation of the native Look and Feel takes precedence over any component-specific indication of rendering. This means that a native Look and Feel should render in a way that is consistent with the platform, even if it contradicts component setting-specific documentation. Examples include
These caveats must not be construed as an excuse to arbitrarily ignore these properties. They are intended to support the requirement that the platform Look and Feel be as consistent with the native rendering as is practical.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Class and Description |
|---|---|
| private static class | UIManager.
This class defines the state managed by the |
| public static class | UIManager.
Provides a little information about an installed
|
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| private static final Object | |
| private static final String | |
| private static final String | |
| private static UIManager. | installedLAFs
The default value of |
| private static final String | |
| private static final UIManager. | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static void | addAuxiliaryLookAndFeel(LookAndFeel
the laf)LookAndFeel objectAdds a |
| public static void | addPropertyChangeListener(PropertyChangeListener
the listener)PropertyChangeListener to be addedAdds a |
| private static void | |
| public static LookAndFeel | Returns: the built-inLookAndFeel objecta name)String specifying the name of the built-in
look and feelCreates a supported built-in Java |
| public static Object | |
| public static Object | |
| public static LookAndFeel[] | Returns: list of auxiliaryLookAndFeels or nullReturns the list of auxiliary look and feels (can be |
| public static boolean | Returns: the boolean value corresponding to the keyan key)Object specifying the key for the desired boolean valueReturns a boolean from the defaults which is associated with the key value. |
| public static boolean | Returns: the boolean value corresponding to the keyan key, Locale Object specifying the key for the desired
boolean valuethe l)Locale for which the boolean is desired; refer
to UIDefaults for details on how a null
Locale is handledReturns a boolean from the defaults which is associated with
the key value and the given |
| public static Border | |
| public static Border | |
| public static Color | |
| public static Color | |
| public static String | Returns: a string with the JLF implementation-classReturns the name of the |
| public static UIDefaults | |
| public static Dimension | Returns: theDimension objectan key)Object specifying the dimension objectReturns a dimension from the defaults. |
| public static Dimension | Returns: theDimension objectan key, Locale Object specifying the dimension objectthe l)Locale for which the object is desired; refer
to UIDefaults for details on how a null
Locale is handledReturns a dimension from the defaults that is appropriate for the given locale. |
| public static Font | |
| public static Font | |
| public static Icon | |
| public static Icon | |
| public static Insets | |
| public static Insets | |
| public static UIManager. | Returns: an array ofLookAndFeelInfo objectsReturns an array of |
| public static int | |
| public static int | |
| private static UIManager. | |
| public static LookAndFeel | |
| public static UIDefaults | Returns: UIDefaults from the current look and feelReturns the |
| private static LookAndFeel | |
| public static PropertyChangeListener[] | Returns: all of thePropertyChangeListeners added or an empty
array if no listeners have been addedReturns an array of all the |
| public static String | |
| public static String | |
| pack-priv static String | |
| public static String | Returns: theString of the LookAndFeel
classReturns the name of the |
| public static ComponentUI | Returns: theComponentUI object for targetthe target)JComponent to return the
ComponentUI forReturns the appropriate |
| private static void | |
| private static void | |
| private static void | initializeDefaultLAF(Properties swingProps)
If the user has specified a default look and feel, use that. |
| private static void | initializeInstalledLAFs(Properties swingProps)
If a |
| private static void | |
| public static void | installLookAndFeel(UIManager.
a infoLookAndFeelInfo object that names the
look and feel and identifies the class that implements itAdds the specified look and feel to the set of available look and feels. |
| public static void | installLookAndFeel(String
descriptive name of the look and feel name, String name of the class that implements the look and feel className)Adds the specified look and feel to the set of available look and feels. |
| private static boolean | |
| private static Properties | |
| private static String | makeInstalledLAFKey(String laf, String attr)
Return a |
| private static String | makeSwingPropertiesFilename()
The location of the |
| private static void | |
| private static void | |
| public static Object | |
| public static boolean | Returns: true if theLookAndFeel was removed from the listthe laf)LookAndFeel to be removedRemoves a |
| public static void | removePropertyChangeListener(PropertyChangeListener
the listener)PropertyChangeListener to be removedRemoves a |
| public static void | setInstalledLookAndFeels(UIManager.
set of infosLookAndFeelInfo objects specifying
the available look and feelsSets the set of available look and feels. |
| public static void | setLookAndFeel(LookAndFeel
LookAndFeel to installSets the current look and feel to |
| public static void | setLookAndFeel(String
a string specifying the name of the class that implements
the look and feel className)Loads the |