javax.swing
Class UIManager

java.lang.Object
  extended by javax.swing.UIManager
All Implemented Interfaces:
Serializable

public class UIManager
extends Object
implements Serializable

Manages the current LookAndFeel and any auxiliary LookAndFeel instances.

See Also:
Serialized Form

Nested Class Summary
static class UIManager.LookAndFeelInfo
          Represents the basic information about a 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 void addAuxiliaryLookAndFeel(LookAndFeel laf)
          Add a LookAndFeel to the list of auxiliary look and feels.
static void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
static Object get(Object key)
          Returns an object from the UIDefaults table for the current LookAndFeel.
static Object get(Object key, Locale locale)
          Returns an object from the UIDefaults table for the current LookAndFeel.
static LookAndFeel[] getAuxiliaryLookAndFeels()
          Returns an array (possibly null) containing the auxiliary LookAndFeels that are in use.
static boolean getBoolean(Object key)
          Returns a boolean value from the defaults table.
static boolean getBoolean(Object key, Locale locale)
          Returns a boolean value from the defaults table.
static Border getBorder(Object key)
          Returns a border from the defaults table.
static Border getBorder(Object key, Locale locale)
          Returns a border from the defaults table.
static Color getColor(Object key)
          Returns a drawing color from the defaults table.
static Color getColor(Object key, Locale locale)
          Returns a drawing color from the defaults table.
static String getCrossPlatformLookAndFeelClassName()
          The fully qualified class name of the cross platform (Metal) look and feel.
static UIDefaults getDefaults()
          Returns the default values for this look and feel.
static Dimension getDimension(Object key)
          Returns a dimension from the defaults table.
static Dimension getDimension(Object key, Locale locale)
          Returns a dimension from the defaults table.
static Font getFont(Object key)
          Retrieves a font from the defaults table of the current LookAndFeel.
static Font getFont(Object key, Locale locale)
          Retrieves a font from the defaults table of the current LookAndFeel.
static Icon getIcon(Object key)
          Returns an icon from the defaults table.
static Icon getIcon(Object key, Locale locale)
          Returns an icon from the defaults table.
static Insets getInsets(Object key)
          Returns an Insets object from the defaults table.
static Insets getInsets(Object key, Locale locale)
          Returns an Insets object from the defaults table.
static UIManager.LookAndFeelInfo[] getInstalledLookAndFeels()
          Returns an array containing information about the LookAndFeels that are installed.
static int getInt(Object key)
          Returns the integer value of the Integer associated with the given key.
static int getInt(Object key, Locale locale)
          Returns the integer value of the Integer associated with the given key.
static LookAndFeel getLookAndFeel()
          Returns the current look and feel (which may be null).
static UIDefaults getLookAndFeelDefaults()
          Returns the UIDefaults table of the currently active look and feel.
static PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all added PropertyChangeListener objects.
static String getString(Object key)
          Returns the String associated with the given key.
static String getString(Object key, Locale locale)
          Returns the String associated with the given key.
static String getSystemLookAndFeelClassName()
          Returns the name of the 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 ComponentUI getUI(JComponent target)
          Returns UI delegate from the current LookAndFeel that renders the target component.
static void installLookAndFeel(String name, String className)
          Creates a new look and feel and adds it to the current array.
static void installLookAndFeel(UIManager.LookAndFeelInfo info)
          Adds the specified look and feel to the current array and then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).
static Object put(Object key, Object value)
          Stores an object in the defaults table.
static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
          Removes a LookAndFeel (LAF) from the list of auxiliary LAFs.
static void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos)
          Replaces the current array of installed LookAndFeelInfos.
static void setLookAndFeel(LookAndFeel newLookAndFeel)
          Sets the current LookAndFeel.
static void setLookAndFeel(String className)
          Set the current default look and feel using a class name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

addPropertyChangeListener

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

Parameters:
listener - the listener to add

removePropertyChangeListener

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

Parameters:
listener - the listener to remove

getPropertyChangeListeners

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

Returns:
an array of listeners
Since:
1.4

addAuxiliaryLookAndFeel

public static void addAuxiliaryLookAndFeel(LookAndFeel laf)
Add a 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()

removeAuxiliaryLookAndFeel

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

Parameters:
laf - the LAF to remove.
Returns:
true if the LAF was removed, and false otherwise.

getAuxiliaryLookAndFeels

public static LookAndFeel[] getAuxiliaryLookAndFeels()
Returns an array (possibly null) containing the auxiliary LookAndFeels that are in use. These are used by the MultiLookAndFeel class.

Returns:
The auxiliary look and feels (possibly null).
See Also:
addAuxiliaryLookAndFeel(LookAndFeel)

get

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

Parameters:
key - the key.
Returns:
The object.

get

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

Parameters:
key - the key.
Returns:
The object.
Since:
1.4

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 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 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 UIDefaults for the current 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 LookAndFeels 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 Integer associated with the given key. If there is no value, or the value is not an instance of 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 Integer associated with the given key. If there is no value, or the value is not an instance of 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(LookAndFeel)

getLookAndFeelDefaults

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

Returns:
The UIDefaults for the current LookAndFeel.

getString

public static String getString(Object key)
Returns the String associated with the given key. If the value is not a 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 String associated with the given key. If the value is not a 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 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 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.

setInstalledLookAndFeels

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


setLookAndFeel

public static void setLookAndFeel(LookAndFeel newLookAndFeel)
                           throws UnsupportedLookAndFeelException
Sets the current 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:
LookAndFeel.isSupportedLookAndFeel()

setLookAndFeel

public static void setLookAndFeel(String className)
                           throws ClassNotFoundException,
                                  InstantiationException,
                                  IllegalAccessException,
                                  UnsupportedLookAndFeelException
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.
ClassNotFoundException
InstantiationException
IllegalAccessException
See Also:
LookAndFeel.isSupportedLookAndFeel()