UIManager (Java 2 Platform SE 5.0) (original) (raw)


javax.swing

Class UIManager

java.lang.Object extended by javax.swing.UIManager

All Implemented Interfaces:

Serializable


public class UIManager

extends Object

implements Serializable

This class keeps track of the current look and feel and its defaults. The default look and feel class is chosen in the following manner:

  1. If the system property swing.defaultlaf is non-null, use it as the default look and feel class name.
  2. If the Properties file swing.properties exists and contains the key swing.defaultlaf, use its value as default look and feel class name. The location ofswing.properties may vary depending upon the implementation of the Java platform. In Sun's implementation this will reside in&java.home>/lib/swing.properties. Refer to the release notes of the implementation you are using for further details.
  3. Otherwise use the Java look and feel.

We manage three levels of defaults: user defaults, look and feel defaults, system defaults. A call to UIManager.get checks all three levels in order and returns the first non-null value for a key, if any. A call to UIManager.put just affects the user defaults. Note that a call to setLookAndFeel doesn't affect the user defaults, it just replaces the middle defaults "level".

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 JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

See Also:

javax.swing.plaf.metal


Nested Class Summary
static class UIManager.LookAndFeelInfo Provides a little information about an installedLookAndFeel for the sake of configuring a menu or for initial application set up.
Constructor Summary
UIManager()
Method Summary
static void addAuxiliaryLookAndFeel(LookAndFeel laf) Adds a LookAndFeel to the list of auxiliary look and feels.
static void addPropertyChangeListener(PropertyChangeListener listener) Adds a PropertyChangeListener to the listener list.
static Object get(Object key) Returns an object from the defaults table.
static Object [get](../../javax/swing/UIManager.html#get%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns an object from the defaults table that is appropriate for the given locale.
static LookAndFeel[] getAuxiliaryLookAndFeels() Returns the list of auxiliary look and feels (can be null).
static boolean getBoolean(Object key) Returns a boolean from the defaults table which is associated with the key value.
static boolean [getBoolean](../../javax/swing/UIManager.html#getBoolean%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns a boolean from the defaults table which is associated with the key value and the given Locale.
static Border getBorder(Object key) Returns a border from the defaults table.
static Border [getBorder](../../javax/swing/UIManager.html#getBorder%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns a border from the defaults table that is appropriate for the given locale.
static Color getColor(Object key) Returns a drawing color from the defaults table.
static Color [getColor](../../javax/swing/UIManager.html#getColor%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns a drawing color from the defaults table that is appropriate for the given locale.
static String getCrossPlatformLookAndFeelClassName() Returns the name of the LookAndFeel class that implements the default cross platform look and feel -- the Java Look and Feel (JLF).
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](../../javax/swing/UIManager.html#getDimension%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns a dimension from the defaults table that is appropriate for the given locale.
static Font getFont(Object key) Returns a drawing font from the defaults table.
static Font [getFont](../../javax/swing/UIManager.html#getFont%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns a drawing font from the defaults table that is appropriate for the given locale.
static Icon getIcon(Object key) Returns an Icon from the defaults table.
static Icon [getIcon](../../javax/swing/UIManager.html#getIcon%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns an Icon from the defaults table that is appropriate for the given locale.
static Insets getInsets(Object key) Returns an Insets object from the defaults table.
static Insets [getInsets](../../javax/swing/UIManager.html#getInsets%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns an Insets object from the defaults table that is appropriate for the given locale.
static UIManager.LookAndFeelInfo[] getInstalledLookAndFeels() Returns an array of objects that provide some information about theLookAndFeel implementations that have been installed with this software development kit.
static int getInt(Object key) Returns an integer from the defaults table.
static int [getInt](../../javax/swing/UIManager.html#getInt%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns an integer from the defaults table that is appropriate for the given locale.
static LookAndFeel getLookAndFeel() Returns the current default look and feel or null.
static UIDefaults getLookAndFeelDefaults() Returns the default values for this look and feel.
static PropertyChangeListener[] getPropertyChangeListeners() Returns an array of all the PropertyChangeListeners added to this UIManager with addPropertyChangeListener().
static String getString(Object key) Returns a string from the defaults table.
static String [getString](../../javax/swing/UIManager.html#getString%28java.lang.Object, java.util.Locale%29)(Object key,Locale l) Returns a string from the defaults table that is appropriate for the given locale.
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 the L&F object that renders the target component.
static void [installLookAndFeel](../../javax/swing/UIManager.html#installLookAndFeel%28java.lang.String, java.lang.String%29)(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](../../javax/swing/UIManager.html#put%28java.lang.Object, java.lang.Object%29)(Object key,Object value) Stores an object in the defaults table.
static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf) Removes a LookAndFeel from the list of auxiliary look and feels.
static void removePropertyChangeListener(PropertyChangeListener listener) Removes 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 default look and feel using aLookAndFeel object.
static void setLookAndFeel(String className) Sets 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](../../java/lang/Object.html#wait%28long, int%29)
Constructor Detail

UIManager

public UIManager()

Method Detail

getInstalledLookAndFeels

public static UIManager.LookAndFeelInfo[] getInstalledLookAndFeels()

Returns an array of objects that provide some information about theLookAndFeel implementations that have been installed with this software development kit. The LookAndFeel info objects can used by an application to construct a menu of look and feel options for the user or to set the look and feel at start up time. Note that we do not return the LookAndFeel classes themselves here to avoid the cost of unnecessarily loading them.

Given a LookAndFeelInfo object one can set the current look and feel like this:

UIManager.setLookAndFeel(info.getClassName());

Returns:

an array of LookAndFeelInfo objects

See Also:

setLookAndFeel(javax.swing.LookAndFeel)


setInstalledLookAndFeels

public static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos) throws SecurityException

Replaces the current array of installed LookAndFeelInfos.

Parameters:

infos - new array of LookAndFeelInfo objects

Throws:

[SecurityException](../../java/lang/SecurityException.html "class in java.lang")

See Also:

getInstalledLookAndFeels()


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[]).

Parameters:

info - a LookAndFeelInfo object that names the look and feel and identifies that class that implements it


installLookAndFeel

public static void installLookAndFeel(String name, String className)

Creates a new look and feel and adds it to the current array. Then calls setInstalledLookAndFeels(javax.swing.UIManager.LookAndFeelInfo[]).

Parameters:

name - a String specifying the name of the look and feel

className - a String specifying the class name that implements the look and feel


getLookAndFeel

public static LookAndFeel getLookAndFeel()

Returns the current default look and feel or null.

Returns:

the current default look and feel, or null

See Also:

setLookAndFeel(javax.swing.LookAndFeel)


setLookAndFeel

public static void setLookAndFeel(LookAndFeel newLookAndFeel) throws UnsupportedLookAndFeelException

Sets the current default look and feel using aLookAndFeel object.

This is a JavaBeans bound property.

Parameters:

newLookAndFeel - the LookAndFeel object

Throws:

[UnsupportedLookAndFeelException](../../javax/swing/UnsupportedLookAndFeelException.html "class in javax.swing") - iflnf.isSupportedLookAndFeel() is false

See Also:

getLookAndFeel()


setLookAndFeel

public static void setLookAndFeel(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException

Sets the current default look and feel using a class name.

Parameters:

className - a string specifying the name of the class that implements the look and feel

Throws:

[ClassNotFoundException](../../java/lang/ClassNotFoundException.html "class in java.lang") - if the LookAndFeel class could not be found

[InstantiationException](../../java/lang/InstantiationException.html "class in java.lang") - if a new instance of the class couldn't be created

[IllegalAccessException](../../java/lang/IllegalAccessException.html "class in java.lang") - if the class or initializer isn't accessible

[UnsupportedLookAndFeelException](../../javax/swing/UnsupportedLookAndFeelException.html "class in javax.swing") - iflnf.isSupportedLookAndFeel() is false


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. If the system property swing.systemlaf has been defined, its value will be returned.

Returns:

the String of the LookAndFeel class

See Also:

setLookAndFeel(javax.swing.LookAndFeel), getCrossPlatformLookAndFeelClassName()


getCrossPlatformLookAndFeelClassName

public static String getCrossPlatformLookAndFeelClassName()

Returns the name of the LookAndFeel class that implements the default cross platform look and feel -- the Java Look and Feel (JLF). If the system propertyswing.crossplatformlaf has been defined, its value will be returned.

Returns:

a string with the JLF implementation-class

See Also:

setLookAndFeel(javax.swing.LookAndFeel), getSystemLookAndFeelClassName()


getDefaults

public static UIDefaults getDefaults()

Returns the default values for this look and feel.

Returns:

a UIDefaults object containing the default values


getFont

public static Font getFont(Object key)

Returns a drawing font from the defaults table.

Parameters:

key - an Object specifying the font

Returns:

the Font object


getFont

public static Font getFont(Object key, Locale l)

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

Parameters:

key - an Object specifying the font

l - the Locale for which the font is desired

Returns:

the Font object

Since:

1.4


getColor

public static Color getColor(Object key)

Returns a drawing color from the defaults table.

Parameters:

key - an Object specifying the color

Returns:

the Color object


getColor

public static Color getColor(Object key, Locale l)

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

Parameters:

key - an Object specifying the color

l - the Locale for which the color is desired

Returns:

the Color object

Since:

1.4


getIcon

public static Icon getIcon(Object key)

Returns an Icon from the defaults table.

Parameters:

key - an Object specifying the icon

Returns:

the Icon object


getIcon

public static Icon getIcon(Object key, Locale l)

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

Parameters:

key - an Object specifying the icon

l - the Locale for which the icon is desired

Returns:

the Icon object

Since:

1.4


getBorder

public static Border getBorder(Object key)

Returns a border from the defaults table.

Parameters:

key - an Object specifying the border

Returns:

the Border object


getBorder

public static Border getBorder(Object key, Locale l)

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

Parameters:

key - an Object specifying the border

l - the Locale for which the border is desired

Returns:

the Border object

Since:

1.4


getString

public static String getString(Object key)

Returns a string from the defaults table.

Parameters:

key - an Object specifying the string

Returns:

the String


getString

public static String getString(Object key, Locale l)

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

Parameters:

key - an Object specifying the string

l - the Locale for which the string is desired

Returns:

the String


getInt

public static int getInt(Object key)

Returns an integer from the defaults table.

Parameters:

key - an Object specifying the int

Returns:

the int


getInt

public static int getInt(Object key, Locale l)

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

Parameters:

key - an Object specifying the int

l - the Locale for which the int is desired

Returns:

the int

Since:

1.4


getBoolean

public static boolean getBoolean(Object key)

Returns a boolean from the defaults table which is associated with the key value. If the key is not found or the key doesn't represent a boolean value then false will be returned.

Parameters:

key - an Object specifying the key for the desired boolean value

Returns:

the boolean value corresponding to the key

Since:

1.4


getBoolean

public static boolean getBoolean(Object key, Locale l)

Returns a boolean from the defaults table which is associated with the key value and the given Locale. If the key is not found or the key doesn't represent a boolean value then false will be returned.

Parameters:

key - an Object specifying the key for the desired boolean value

l - the Locale for which the boolean is desired

Returns:

the boolean value corresponding to the key

Since:

1.4


getInsets

public static Insets getInsets(Object key)

Returns an Insets object from the defaults table.

Parameters:

key - an Object specifying the Insets object

Returns:

the Insets object


getInsets

public static Insets getInsets(Object key, Locale l)

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

Parameters:

key - an Object specifying the Insets object

l - the Locale for which the object is desired

Returns:

the Insets object

Since:

1.4


getDimension

public static Dimension getDimension(Object key)

Returns a dimension from the defaults table.

Parameters:

key - an Object specifying the dimension object

Returns:

the Dimension object


getDimension

public static Dimension getDimension(Object key, Locale l)

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

Parameters:

key - an Object specifying the dimension object

l - the Locale for which the object is desired

Returns:

the Dimension object

Since:

1.4


get

public static Object get(Object key)

Returns an object from the defaults table.

Parameters:

key - an Object specifying the desired object

Returns:

the Object


get

public static Object get(Object key, Locale l)

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

Parameters:

key - an Object specifying the desired object

l - the Locale for which the object is desired

Returns:

the Object


put

public static Object put(Object key, Object value)

Stores an object in the defaults table.

Parameters:

key - an Object specifying the retrieval key

value - the Object to store

Returns:

the Object returned by [UIDefaults.put(java.lang.Object, java.lang.Object)](../../javax/swing/UIDefaults.html#put%28java.lang.Object, java.lang.Object%29)


getUI

public static ComponentUI getUI(JComponent target)

Returns the L&F object that renders the target component.

Parameters:

target - the JComponent to render

Returns:

the ComponentUI object that renders the target component


getLookAndFeelDefaults

public static UIDefaults getLookAndFeelDefaults()

Returns the default values for this look and feel.

Returns:

an UIDefaults object containing the default values


addAuxiliaryLookAndFeel

public static void addAuxiliaryLookAndFeel(LookAndFeel laf)

Adds a LookAndFeel to the list of auxiliary look and feels. The auxiliary look and feels tell the multiplexing look and feel what other LookAndFeel classes for a component instance are to be used in addition to the default LookAndFeel class when creating a multiplexing UI. The change will only take effect when a new UI class is created or when the default look and feel is changed on a component instance.

Note these are not the same as the installed look and feels.

Parameters:

laf - the LookAndFeel object

See Also:

removeAuxiliaryLookAndFeel(javax.swing.LookAndFeel), setLookAndFeel(javax.swing.LookAndFeel), getAuxiliaryLookAndFeels(), getInstalledLookAndFeels()


removeAuxiliaryLookAndFeel

public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)

Removes a LookAndFeel from the list of auxiliary look and feels. The auxiliary look and feels tell the multiplexing look and feel what other LookAndFeel classes for a component instance are to be used in addition to the default LookAndFeel class when creating a multiplexing UI. The change will only take effect when a new UI class is created or when the default look and feel is changed on a component instance.

Note these are not the same as the installed look and feels.

Returns:

true if the LookAndFeel was removed from the list

See Also:

removeAuxiliaryLookAndFeel(javax.swing.LookAndFeel), getAuxiliaryLookAndFeels(), setLookAndFeel(javax.swing.LookAndFeel), getInstalledLookAndFeels()


getAuxiliaryLookAndFeels

public static LookAndFeel[] getAuxiliaryLookAndFeels()

Returns the list of auxiliary look and feels (can be null). The auxiliary look and feels tell the multiplexing look and feel what other LookAndFeel classes for a component instance are to be used in addition to the default LookAndFeel class when creating a multiplexing UI.

Note these are not the same as the installed look and feels.

Returns:

list of auxiliary LookAndFeels or null

See Also:

addAuxiliaryLookAndFeel(javax.swing.LookAndFeel), removeAuxiliaryLookAndFeel(javax.swing.LookAndFeel), setLookAndFeel(javax.swing.LookAndFeel), getInstalledLookAndFeels()


addPropertyChangeListener

public static void addPropertyChangeListener(PropertyChangeListener listener)

Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

Parameters:

listener - the PropertyChangeListener to be added

See Also:

PropertyChangeSupport


removePropertyChangeListener

public static void removePropertyChangeListener(PropertyChangeListener listener)

Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Parameters:

listener - the PropertyChangeListener to be removed

See Also:

PropertyChangeSupport


getPropertyChangeListeners

public static PropertyChangeListener[] getPropertyChangeListeners()

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

Returns:

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

Since:

1.4



Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.

Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.