APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing

public Class UIManager

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@SuppressWarnings:serial
Imports
java.awt.Component, .Font, .Color, .Insets, .Dimension, .KeyboardFocusManager, .KeyEventPostProcessor, .Toolkit, java.awt.event.KeyEvent, javax.swing.plaf.ComponentUI, javax.swing.border.Border, javax.swing.event.SwingPropertyChangeSupport, java.beans.PropertyChangeListener, java.io.Serializable, .File, .FileInputStream, java.util.ArrayList, .Properties, .StringTokenizer, .Vector, .Locale, .HashMap, .Objects, sun.awt.SunToolkit, .OSInfo, .AWTAccessor, sun.swing.SwingUtilities2, .SwingAccessor

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.

Specifying the look and feel

The look and feel can be specified in two distinct ways: by specifying the fully qualified name of the class for the look and feel, or by creating an instance of 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.

Default look and feel

The class used for the default look and feel is chosen in the following manner:
  1. If the system property swing.defaultlaf is non-null, use its value as the default look and feel class name.
  2. If the 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.
  3. Otherwise use the cross platform look and feel.

Defaults

UIManager manages three sets of UIDefaults. In order, they are:
  1. Developer defaults. With few exceptions Swing does not alter the developer defaults; these are intended to be modified and used by the developer.
  2. Look and feel defaults. The look and feel defaults are supplied by the look and feel at the time it is installed as the current look and feel (setLookAndFeel() is invoked). The look and feel defaults can be obtained using the getLookAndFeelDefaults() method.
  3. System defaults. The system defaults are provided by Swing.
Invoking any of the various 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.

System Look and Feels

[The terms "System", "Native" and "Platform" may be used interchangeably in this context].

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 are just examples. Not an exhaustive list.

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.beans.XMLEncoder.

Authors
Thomas Ball, Hans Muller
Since
1.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
UIManager.LAFState

This class defines the state managed by the UIManager.

public static class
UIManager.LookAndFeelInfo

Provides a little information about an installed LookAndFeel for the sake of configuring a menu or for initial application set up.

Field Summary

Modifier and TypeField and Description
private static final String
private static final Object
private static final String
private static final String
private static UIManager.LookAndFeelInfo[]
installedLAFs

The default value of installedLAFS is used when no swing.properties file is available or if the file doesn't contain a "swing.installedlafs" property.

private static final String
private static final UIManager.LAFState
private static final String

Constructor Summary

AccessConstructor and Description
public
UIManager()

Constructs a UIManager.

Method Summary

Modifier and TypeMethod and Description
public static void
addAuxiliaryLookAndFeel(LookAndFeel
the LookAndFeel object
laf
)

Adds a LookAndFeel to the list of auxiliary look and feels.

public static void
addPropertyChangeListener(PropertyChangeListener
the PropertyChangeListener to be added
listener
)

Adds a PropertyChangeListener to the listener list.

private static void
public static LookAndFeel

Returns:

the built-in LookAndFeel object
createLookAndFeel
(String
a String specifying the name of the built-in look and feel
name
)

Creates a supported built-in Java LookAndFeel specified by the given L&F; name name.

public static Object

Returns:

the Object
get
(Object
an Object specifying the desired object
key
)

Returns an object from the defaults.

public static Object

Returns:

the Object
get
(Object
an Object specifying the desired object
key
,
Locale
the Locale for which the object is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns an object from the defaults that is appropriate for the given locale.

public static LookAndFeel[]

Returns:

list of auxiliary LookAndFeels or null
getAuxiliaryLookAndFeels
()

Returns the list of auxiliary look and feels (can be null).

public static boolean

Returns:

the boolean value corresponding to the key
getBoolean
(Object
an Object specifying the key for the desired boolean value
key
)

Returns a boolean from the defaults which is associated with the key value.

public static boolean

Returns:

the boolean value corresponding to the key
getBoolean
(Object
an Object specifying the key for the desired boolean value
key
,
Locale
the Locale for which the boolean is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns a boolean from the defaults which is associated with the key value and the given Locale.

public static Border

Returns:

the Border object
getBorder
(Object
an Object specifying the border
key
)

Returns a border from the defaults.

public static Border

Returns:

the Border object
getBorder
(Object
an Object specifying the border
key
,
Locale
the Locale for which the border is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns a border from the defaults that is appropriate for the given locale.

public static Color

Returns:

the Color object
getColor
(Object
an Object specifying the color
key
)

Returns a color from the defaults.

public static Color

Returns:

the Color object
getColor
(Object
an Object specifying the color
key
,
Locale
the Locale for which the color is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns a color from the defaults that is appropriate for the given locale.

public static String

Returns:

a string with the JLF implementation-class
getCrossPlatformLookAndFeelClassName
()

Returns the name of the LookAndFeel class that implements the default cross platform look and feel -- the Java Look and Feel (JLF).

public static UIDefaults

Returns:

a UIDefaults object containing the default values
getDefaults
()

Returns the defaults.

public static Dimension

Returns:

the Dimension object
getDimension
(Object
an Object specifying the dimension object
key
)

Returns a dimension from the defaults.

public static Dimension

Returns:

the Dimension object
getDimension
(Object
an Object specifying the dimension object
key
,
Locale
the Locale for which the object is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns a dimension from the defaults that is appropriate for the given locale.

public static Font

Returns:

the Font object
getFont
(Object
an Object specifying the font
key
)

Returns a font from the defaults.

public static Font

Returns:

the Font object
getFont
(Object
an Object specifying the font
key
,
Locale
the Locale for which the font is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns a font from the defaults that is appropriate for the given locale.

public static Icon

Returns:

the Icon object
getIcon
(Object
an Object specifying the icon
key
)

Returns an Icon from the defaults.

public static Icon

Returns:

the Icon object
getIcon
(Object
an Object specifying the icon
key
,
Locale
the Locale for which the icon is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns an Icon from the defaults that is appropriate for the given locale.

public static Insets

Returns:

the Insets object
getInsets
(Object
an Object specifying the Insets object
key
)

Returns an Insets object from the defaults.

public static Insets

Returns:

the Insets object
getInsets
(Object
an Object specifying the Insets object
key
,
Locale
the Locale for which the object is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns an Insets object from the defaults that is appropriate for the given locale.

public static UIManager.LookAndFeelInfo[]

Returns:

an array of LookAndFeelInfo objects
getInstalledLookAndFeels
()

Returns an array of LookAndFeelInfos representing the LookAndFeel implementations currently available.

public static int

Returns:

the int
getInt
(Object
an Object specifying the int
key
)

Returns an integer from the defaults.

public static int

Returns:

the int
getInt
(Object
an Object specifying the int
key
,
Locale
the Locale for which the int is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns an integer from the defaults that is appropriate for the given locale.

private static UIManager.LAFState
getLAFState()

Return the LAFState object.

public static LookAndFeel

Returns:

current look and feel, or null
getLookAndFeel
()

Returns the current look and feel or null.

public static UIDefaults

Returns:

UIDefaults from the current look and feel
getLookAndFeelDefaults
()

Returns the UIDefaults from the current look and feel, that were obtained at the time the look and feel was installed.

private static LookAndFeel
getMultiLookAndFeel()

Finds the Multiplexing LookAndFeel.

public static PropertyChangeListener[]

Returns:

all of the PropertyChangeListeners added or an empty array if no listeners have been added
getPropertyChangeListeners
()

Returns an array of all the PropertyChangeListeners added to this UIManager with addPropertyChangeListener().

public static String

Returns:

the String
getString
(Object
an Object specifying the string
key
)

Returns a string from the defaults.

public static String

Returns:

the String
getString
(Object
an Object specifying the string
key
,
Locale
the Locale for which the string is desired; refer to UIDefaults for details on how a null Locale is handled
l
)

Returns a string from the defaults that is appropriate for the given locale.

pack-priv static String

Returns:

the String
getString
(Object
an Object specifying the string
key
,
Component
Component used to determine the locale; null implies the default locale as returned by Locale.getDefault()
c
)

Returns a string from the defaults that is appropriate for the given locale.

public static String

Returns:

the String of the LookAndFeel class
getSystemLookAndFeelClassName
()

Returns the name of the LookAndFeel class that implements the native system look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.

public static ComponentUI

Returns:

the ComponentUI object for target
getUI
(JComponent
the JComponent to return the ComponentUI for
target
)

Returns the appropriate ComponentUI implementation for target.

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 swing.properties file exist and it has a swing.installedlafs property then initialize the installedLAFs field.

private static void
public static void
installLookAndFeel(UIManager.LookAndFeelInfo
a LookAndFeelInfo object that names the look and feel and identifies the class that implements it
info
)

Adds 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 swing.properties file key for the attribute of specified look and feel.

private static String
makeSwingPropertiesFilename()

The location of the swing.properties property file is implementation-specific.

private static void
private static void
public static Object

Returns:

the Object returned by UIDefaults#put
put
(Object
an Object specifying the retrieval key
key
,
Object
the Object to store; refer to UIDefaults for details on how null is handled
value
)

Stores an object in the developer defaults.

public static boolean

Returns:

true if the LookAndFeel was removed from the list
removeAuxiliaryLookAndFeel
(LookAndFeel
the LookAndFeel to be removed
laf
)

Removes a LookAndFeel from the list of auxiliary look and feels.

public static void
removePropertyChangeListener(PropertyChangeListener
the PropertyChangeListener to be removed
listener
)

Removes a PropertyChangeListener from the listener list.

public static void
setInstalledLookAndFeels(UIManager.LookAndFeelInfo[]
set of LookAndFeelInfo objects specifying the available look and feels
infos
)

Sets the set of available look and feels.

public static void
setLookAndFeel(LookAndFeel
LookAndFeel to install
newLookAndFeel
)

Sets the current look and feel to newLookAndFeel.

public static void
setLookAndFeel(String
a string specifying the name of the class that implements the look and feel
className
)

Loads the LookAndFeel specified by the given class name, using the current thread's context class loader, and passes it to setLookAndFeel(LookAndFeel).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait