javax.swing

Class UIManager

public class UIManager extends Object implements Serializable

Manages the current {@link LookAndFeel} and any auxiliary {@link LookAndFeel} instances.
Nested Class Summary
static classUIManager.LookAndFeelInfo
Represents the basic information about a {@link LookAndFeel} (LAF), so that a list of installed LAFs can be presented without actually loading the LAF class(es).
Constructor Summary
UIManager()
Creates a new instance of the UIManager.
Method Summary
static voidaddAuxiliaryLookAndFeel(LookAndFeel laf)
Add a {@link LookAndFeel} to the list of auxiliary look and feels.
static voidaddPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.
static Objectget(Object key)
Returns an object from the {@link UIDefaults} table for the current {@link LookAndFeel}.
static Objectget(Object key, Locale locale)
Returns an object from the {@link UIDefaults} table for the current {@link LookAndFeel}.
static LookAndFeel[]getAuxiliaryLookAndFeels()
Returns an array (possibly null) containing the auxiliary {@link LookAndFeel}s that are in use.
static booleangetBoolean(Object key)
Returns a boolean value from the defaults table.
static booleangetBoolean(Object key, Locale locale)
Returns a boolean value from the defaults table.
static BordergetBorder(Object key)
Returns a border from the defaults table.
static BordergetBorder(Object key, Locale locale)
Returns a border from the defaults table.
static ColorgetColor(Object key)
Returns a drawing color from the defaults table.
static ColorgetColor(Object key, Locale locale)
Returns a drawing color from the defaults table.
static StringgetCrossPlatformLookAndFeelClassName()
The fully qualified class name of the cross platform (Metal) look and feel.
static UIDefaultsgetDefaults()
Returns the default values for this look and feel.
static DimensiongetDimension(Object key)
Returns a dimension from the defaults table.
static DimensiongetDimension(Object key, Locale locale)
Returns a dimension from the defaults table.
static FontgetFont(Object key)
Retrieves a font from the defaults table of the current LookAndFeel.
static FontgetFont(Object key, Locale locale)
Retrieves a font from the defaults table of the current LookAndFeel.
static IcongetIcon(Object key)
Returns an icon from the defaults table.
static IcongetIcon(Object key, Locale locale)
Returns an icon from the defaults table.
static InsetsgetInsets(Object key)
Returns an Insets object from the defaults table.
static InsetsgetInsets(Object key, Locale locale)
Returns an Insets object from the defaults table.
static UIManager.LookAndFeelInfo[]getInstalledLookAndFeels()
Returns an array containing information about the {@link LookAndFeel}s that are installed.
static intgetInt(Object key)
Returns the integer value of the {@link Integer} associated with the given key.
static intgetInt(Object key, Locale locale)
Returns the integer value of the {@link Integer} associated with the given key.
static LookAndFeelgetLookAndFeel()
Returns the current look and feel (which may be null).
static UIDefaultsgetLookAndFeelDefaults()
Returns the UIDefaults table of the currently active look and feel.
static PropertyChangeListener[]getPropertyChangeListeners()
Returns an array of all added PropertyChangeListener objects.
static StringgetString(Object key)
Returns the {@link String} associated with the given key.
static StringgetString(Object key, Locale locale)
Returns the {@link String} associated with the given key.
static StringgetSystemLookAndFeelClassName()
Returns the name of the {@link LookAndFeel} class that implements the native systems look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.
static ComponentUIgetUI(JComponent target)
Returns UI delegate from the current {@link LookAndFeel} that renders the target component.
static voidinstallLookAndFeel(String name, String className)
Creates a new look and feel and adds it to the current array.
static voidinstallLookAndFeel(UIManager.LookAndFeelInfo info)
Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
static Objectput(Object key, Object value)
Stores an object in the defaults table.
static booleanremoveAuxiliaryLookAndFeel(LookAndFeel laf)
Removes a {@link LookAndFeel} (LAF) from the list of auxiliary LAFs.
static voidremovePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.
static voidsetInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
Replaces the current array of installed LookAndFeelInfos.
static voidsetLookAndFeel(LookAndFeel newLookAndFeel)
Sets the current {@link LookAndFeel}.
static voidsetLookAndFeel(String className)
Set the current default look and feel using a class name.

Constructor Detail

UIManager

public UIManager()
Creates a new instance of the UIManager. There is no need to construct an instance of this class, since all methods are static.

Method Detail

addAuxiliaryLookAndFeel

public static void addAuxiliaryLookAndFeel(LookAndFeel laf)
Add a {@link LookAndFeel} to the list of auxiliary look and feels.

Parameters: laf the auxiliary look and feel (null not permitted).

Throws: NullPointerException if laf is null.

See Also: getAuxiliaryLookAndFeels

addPropertyChangeListener

public static void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to the listener list.

Parameters: listener the listener to add

get

public static Object get(Object key)
Returns an object from the {@link UIDefaults} table for the current {@link LookAndFeel}.

Parameters: key the key.

Returns: The object.

get

public static Object get(Object key, Locale locale)
Returns an object from the {@link UIDefaults} table for the current {@link LookAndFeel}.

Parameters: key the key.

Returns: The object.

Since: 1.4

getAuxiliaryLookAndFeels

public static LookAndFeel[] getAuxiliaryLookAndFeels()
Returns an array (possibly null) containing the auxiliary {@link LookAndFeel}s that are in use. These are used by the {@link javax.swing.plaf.multi.MultiLookAndFeel} class.

Returns: The auxiliary look and feels (possibly null).

See Also: addAuxiliaryLookAndFeel

getBoolean

public static boolean getBoolean(Object key)
Returns a boolean value from the defaults table. If there is no value for the specified key, or the value is not an instance of {@link Boolean}, this method returns false.

Parameters: key the key (null not permitted).

Returns: The boolean value associated with the specified key.

Throws: NullPointerException if key is null.

Since: 1.4

getBoolean

public static boolean getBoolean(Object key, Locale locale)
Returns a boolean value from the defaults table. If there is no value for the specified key, or the value is not an instance of {@link Boolean}, this method returns false.

Parameters: key the key (null not permitted). locale the locale.

Returns: The boolean value associated with the specified key.

Throws: NullPointerException if key is null.

Since: 1.4

getBorder

public static Border getBorder(Object key)
Returns a border from the defaults table.

Parameters: key the key (null not permitted).

Returns: The border associated with the given key, or null.

Throws: NullPointerException if key is null.

getBorder

public static Border getBorder(Object key, Locale locale)
Returns a border from the defaults table.

Parameters: key the key (null not permitted). locale the locale.

Returns: The border associated with the given key, or null.

Throws: NullPointerException if key is null.

Since: 1.4

getColor

public static Color getColor(Object key)
Returns a drawing color from the defaults table.

Parameters: key the key (null not permitted).

Returns: The color associated with the given key, or null.

Throws: NullPointerException if key is null.

getColor

public static Color getColor(Object key, Locale locale)
Returns a drawing color from the defaults table.

Parameters: key the key (null not permitted). locale the locale.

Returns: The color associated with the given key, or null.

Throws: NullPointerException if key is null.

Since: 1.4

getCrossPlatformLookAndFeelClassName

public static String getCrossPlatformLookAndFeelClassName()
The fully qualified class name of the cross platform (Metal) look and feel. This string can be passed to Class.forName()

Returns: "javax.swing.plaf.metal.MetalLookAndFeel"

getDefaults

public static UIDefaults getDefaults()
Returns the default values for this look and feel.

Returns: The {@link UIDefaults} for the current {@link LookAndFeel}.

getDimension

public static Dimension getDimension(Object key)
Returns a dimension from the defaults table.

Parameters: key the key (null not permitted).

Returns: The color associated with the given key, or null.

Throws: NullPointerException if key is null.

getDimension

public static Dimension getDimension(Object key, Locale locale)
Returns a dimension from the defaults table.

Parameters: key the key (null not permitted). locale the locale.

Returns: The color associated with the given key, or null.

Throws: NullPointerException if key is null.

Since: 1.4

getFont

public static Font getFont(Object key)
Retrieves a font from the defaults table of the current LookAndFeel.

Parameters: key an Object that specifies the font. Typically, this is a String such as TitledBorder.font.

Returns: The font associated with the given key, or null.

Throws: NullPointerException if key is null.

getFont

public static Font getFont(Object key, Locale locale)
Retrieves a font from the defaults table of the current LookAndFeel.

Parameters: key an Object that specifies the font. Typically, this is a String such as TitledBorder.font. locale the locale.

Returns: The font associated with the given key, or null.

Throws: NullPointerException if key is null.

Since: 1.4

getIcon

public static Icon getIcon(Object key)
Returns an icon from the defaults table.

Parameters: key the key (null not permitted).

Returns: The icon associated with the given key, or null.

Throws: NullPointerException if key is null.

getIcon

public static Icon getIcon(Object key, Locale locale)
Returns an icon from the defaults table.

Parameters: key the key (null not permitted). locale the locale.

Returns: The icon associated with the given key, or null.

Throws: NullPointerException if key is null.

Since: 1.4

getInsets

public static Insets getInsets(Object key)
Returns an Insets object from the defaults table.

Parameters: key the key (null not permitted).

Returns: The insets associated with the given key, or null.

Throws: NullPointerException if key is null.

getInsets

public static Insets getInsets(Object key, Locale locale)
Returns an Insets object from the defaults table.

Parameters: key the key (null not permitted). locale the locale.

Returns: The insets associated with the given key, or null.

Throws: NullPointerException if key is null.

Since: 1.4

getInstalledLookAndFeels

public static UIManager.LookAndFeelInfo[] getInstalledLookAndFeels()
Returns an array containing information about the {@link LookAndFeel}s that are installed.

Returns: A list of the look and feels that are available (installed).

getInt

public static int getInt(Object key)
Returns the integer value of the {@link Integer} associated with the given key. If there is no value, or the value is not an instance of {@link Integer}, this method returns 0.

Parameters: key the key (null not permitted).

Returns: The integer value associated with the given key, or 0.

getInt

public static int getInt(Object key, Locale locale)
Returns the integer value of the {@link Integer} associated with the given key. If there is no value, or the value is not an instance of {@link Integer}, this method returns 0.

Parameters: key the key (null not permitted). locale the locale.

Returns: The integer value associated with the given key, or 0.

Since: 1.4

getLookAndFeel

public static LookAndFeel getLookAndFeel()
Returns the current look and feel (which may be null).

Returns: The current look and feel.

See Also: setLookAndFeel

getLookAndFeelDefaults

public static UIDefaults getLookAndFeelDefaults()
Returns the UIDefaults table of the currently active look and feel.

Returns: The {@link UIDefaults} for the current {@link LookAndFeel}.

getPropertyChangeListeners

public static PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all added PropertyChangeListener objects.

Returns: an array of listeners

Since: 1.4

getString

public static String getString(Object key)
Returns the {@link String} associated with the given key. If the value is not a {@link String}, this method returns null.

Parameters: key the key (null not permitted).

Returns: The string associated with the given key, or null.

getString

public static String getString(Object key, Locale locale)
Returns the {@link String} associated with the given key. If the value is not a {@link String}, this method returns null.

Parameters: key the key (null not permitted). locale the locale.

Returns: The string associated with the given key, or null.

Since: 1.4

getSystemLookAndFeelClassName

public static String getSystemLookAndFeelClassName()
Returns the name of the {@link LookAndFeel} class that implements the native systems look and feel if there is one, otherwise the name of the default cross platform LookAndFeel class.

Returns: The fully qualified class name for the system look and feel.

See Also: getCrossPlatformLookAndFeelClassName

getUI

public static ComponentUI getUI(JComponent target)
Returns UI delegate from the current {@link LookAndFeel} that renders the target component.

Parameters: target the target component.

installLookAndFeel

public static void installLookAndFeel(String name, String className)
Creates a new look and feel and adds it to the current array.

Parameters: name the look and feel name. className the fully qualified name of the class that implements the look and feel.

installLookAndFeel

public static void installLookAndFeel(UIManager.LookAndFeelInfo info)
Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).

put

public static Object put(Object key, Object value)
Stores an object in the defaults table.

Parameters: key the key. value the value.

removeAuxiliaryLookAndFeel

public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
Removes a {@link LookAndFeel} (LAF) from the list of auxiliary LAFs.

Parameters: laf the LAF to remove.

Returns: true if the LAF was removed, and false otherwise.

removePropertyChangeListener

public static void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.

Parameters: listener the listener to remove

setInstalledLookAndFeels

public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
Replaces the current array of installed LookAndFeelInfos.

setLookAndFeel

public static void setLookAndFeel(LookAndFeel newLookAndFeel)
Sets the current {@link LookAndFeel}.

Parameters: newLookAndFeel the new look and feel (null permitted).

Throws: UnsupportedLookAndFeelException if the look and feel is not supported on the current platform.

See Also: isSupportedLookAndFeel

setLookAndFeel

public static void setLookAndFeel(String className)
Set the current default look and feel using a class name.

Parameters: className the look and feel class name.

Throws: UnsupportedLookAndFeelException if the look and feel is not supported on the current platform.

See Also: isSupportedLookAndFeel