| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public class UIManager extends Object implements Serializable
{@code UIManager} manages the current look and feel, the set of available look and feels, {@code PropertyChangeListeners} that are notified when the look and feel changes, look and feel defaults, and convenience methods for obtaining various default values.
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 {@code updateUI} on all {@code JComponents}. The method {@link SwingUtilities#updateComponentTreeUI} makes it easy to apply {@code updateUI} to a containment hierarchy. Refer to it for details. The exact behavior of not invoking {@code updateUI} after changing the look and feel is unspecified. It is very possible to receive unexpected exceptions, painting problems, or worse.
swing.defaultlaf
is
{@code non-null}, use its value as the default look and feel class
name.
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. In Sun's implementation
the location is ${java.home}/lib/swing.properties
.
Refer to the release notes of the implementation being used for
further details.
It's important to note that {@code getDefaults} returns a custom instance of {@code UIDefaults} with this resolution logic built into it. For example, {@code UIManager.getDefaults().getString("Table.foreground")} is equivalent to {@code 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 {@code UIDefaults} with the resolution logic as previously described.
When the look and feel is changed, {@code UIManager} alters only the look and feel defaults; the developer and system defaults are not altered by the {@code 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 {@code ComponentUI} provided by a look and feel, may access the defaults at different times in their life cycle. Some look and feels may agressively 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 {@code ComponentUI} provided by one look and feel will not work with another look and feel.
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 {@link java.beans.XMLEncoder}.
Nested Class Summary | |
---|---|
static class |
Provides a little information about an installed LookAndFeel for the sake of configuring a menu or
for initial application set up. |
Constructor Summary | |
---|---|
|
Method Summary | |
---|---|
static void |
Adds a LookAndFeel to the list of auxiliary look and feels.
|
static void |
Adds a PropertyChangeListener to the listener list.
|
static Object |
Returns an object from the defaults. |
static Object |
Returns an object from the defaults that is appropriate for the given locale. |
static LookAndFeel[] |
Returns the list of auxiliary look and feels (can be null ).
|
static boolean |
getBoolean(Object key) Returns a boolean from the defaults which is associated with the key value. |
static boolean |
getBoolean(Object key, Locale l) Returns a boolean from the defaults which is associated with the key value and the given Locale .
|
static Border |
Returns a border from the defaults. |
static Border |
Returns a border from the defaults that is appropriate for the given locale. |
static Color |
Returns a color from the defaults. |
static Color |
Returns a color from the defaults that is appropriate for the given locale. |
static String |
Returns the name of the LookAndFeel class that implements
the default cross platform look and feel -- the Java
Look and Feel (JLF).
|
static UIDefaults |
Returns the defaults. |
static Dimension |
getDimension(Object key) Returns a dimension from the defaults. |
static Dimension |
getDimension(Object key, Locale l) Returns a dimension from the defaults that is appropriate for the given locale. |
static Font |
Returns a font from the defaults. |
static Font |
Returns a font from the defaults that is appropriate for the given locale. |
static Icon |
Returns an Icon from the defaults.
|
static Icon |
Returns an Icon from the defaults that is appropriate
for the given locale.
|
static Insets |
Returns an Insets object from the defaults.
|
static Insets |
Returns an Insets object from the defaults that is
appropriate for the given locale.
|
static UIManager.LookAndFeelInfo[] |
Returns an array of s representing the implementations currently available. |
static int |
Returns an integer from the defaults. |
static int |
Returns an integer from the defaults that is appropriate for the given locale. |
static LookAndFeel |
Returns the current look and feel or null .
|
static UIDefaults |
Returns the from the current look and feel, that were obtained at the time the look and feel was installed. |
static PropertyChangeListener[] |
Returns an array of all the PropertyChangeListener s added
to this UIManager with addPropertyChangeListener().
|
static String |
Returns a string from the defaults. |
static String |
Returns a string from the defaults that is appropriate for the given locale. |
static String |
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.
|
static ComponentUI |
getUI(JComponent target) Returns the appropriate implementation for . |
static void |
installLookAndFeel(String name, String className) Adds the specified look and feel to the set of available look and feels. |
static void |
Adds the specified look and feel to the set of available look and feels. |
static Object |
Stores an object in the developer defaults. |
static boolean |
Removes a LookAndFeel from the list of auxiliary look and feels.
|
static void |
Removes a PropertyChangeListener from the listener list.
|
static void |
Sets the set of available look and feels. |
static void |
setLookAndFeel(LookAndFeel newLookAndFeel) Sets the current look and feel to . |
static void |
setLookAndFeel(String className) Loads the specified by the given class name, using the current thread's context class loader, and passes it to . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UIManager()
Method Detail |
---|
public static void addAuxiliaryLookAndFeel(LookAndFeel laf)
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.
laf
- the LookAndFeel
objectpublic static void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
to the listener list.
The listener is registered for all properties.
listener
- the PropertyChangeListener
to be addedpublic static Object get(Object key)
key
- an Object
specifying the desired objectObject
public static Object get(Object key, Locale l)
key
- an Object
specifying the desired objectl
- the Locale
for which the object is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledObject
public static LookAndFeel[] getAuxiliaryLookAndFeels()
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.
LookAndFeel
s or null
public static boolean getBoolean(Object key)
key
- an Object
specifying the key for the desired boolean valuepublic static boolean getBoolean(Object key, Locale l)
Locale
. If the key is not
found or the key doesn't represent
a boolean value then {@code false} will be returned.
key
- an Object
specifying the key for the desired
boolean valuel
- the Locale
for which the boolean is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledpublic static Border getBorder(Object key)
key
- an Object
specifying the borderBorder
objectpublic static Border getBorder(Object key, Locale l)
key
- an Object
specifying the borderl
- the Locale
for which the border is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledBorder
objectpublic static Color getColor(Object key)
key
- an Object
specifying the colorColor
objectpublic static Color getColor(Object key, Locale l)
key
- an Object
specifying the colorl
- the Locale
for which the color is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledColor
objectpublic static String getCrossPlatformLookAndFeelClassName()
LookAndFeel
class that implements
the default cross platform look and feel -- the Java
Look and Feel (JLF). This value can be overriden by setting the
swing.crossplatformlaf
system property.
public static UIDefaults getDefaults()
UIDefaults
object containing the default valuespublic static Dimension getDimension(Object key)
key
- an Object
specifying the dimension objectDimension
objectpublic static Dimension getDimension(Object key, Locale l)
key
- an Object
specifying the dimension objectl
- the Locale
for which the object is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledDimension
objectpublic static Font getFont(Object key)
key
- an Object
specifying the fontFont
objectpublic static Font getFont(Object key, Locale l)
key
- an Object
specifying the fontl
- the Locale
for which the font is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledFont
objectpublic static Icon getIcon(Object key)
Icon
from the defaults. If the value for
{@code key} is not an {@code Icon}, {@code null} is returned.
key
- an Object
specifying the iconIcon
objectpublic static Icon getIcon(Object key, Locale l)
Icon
from the defaults that is appropriate
for the given locale. If the value for
{@code key} is not an {@code Icon}, {@code null} is returned.
key
- an Object
specifying the iconl
- the Locale
for which the icon is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledIcon
objectpublic static Insets getInsets(Object key)
Insets
object from the defaults. If the value
for {@code key} is not an {@code Insets}, {@code null} is returned.
key
- an Object
specifying the Insets
objectInsets
objectpublic static Insets getInsets(Object key, Locale l)
Insets
object from the defaults that is
appropriate for the given locale. If the value
for {@code key} is not an {@code Insets}, {@code null} is returned.
key
- an Object
specifying the Insets
objectl
- the Locale
for which the object is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledInsets
objectpublic static UIManager.LookAndFeelInfo[] getInstalledLookAndFeels()
LookAndFeelInfo
objects can be used by an
application to construct a menu of look and feel options for
the user, or to determine which look and feel to set at startup
time. To avoid the penalty of creating numerous {@code
LookAndFeel} objects, {@code LookAndFeelInfo} maintains the
class name of the {@code LookAndFeel} class, not the actual
{@code LookAndFeel} instance.
The following example illustrates setting the current look and feel from an instance of {@code LookAndFeelInfo}:
UIManager.setLookAndFeel(info.getClassName());
LookAndFeelInfo
objectspublic static int getInt(Object key)
key
- an Object
specifying the intpublic static int getInt(Object key, Locale l)
key
- an Object
specifying the intl
- the Locale
for which the int is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledpublic static LookAndFeel getLookAndFeel()
null
.
null
public static UIDefaults getLookAndFeelDefaults()
In general, developers should use the {@code UIDefaults} returned from {@code getDefaults()}. As the current look and feel may expect certain values to exist, altering the {@code UIDefaults} returned from this method could have unexpected results.
UIDefaults
from the current look and feelpublic static PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListener
s added
to this UIManager with addPropertyChangeListener().
PropertyChangeListener
s added or an empty
array if no listeners have been addedpublic static String getString(Object key)
key
- an Object
specifying the stringString
public static String getString(Object key, Locale l)
key
- an Object
specifying the stringl
- the Locale
for which the string is desired; refer
to {@code UIDefaults} for details on how a {@code null}
{@code Locale} is handledString
public static String getSystemLookAndFeelClassName()
LookAndFeel
class that implements
the native system look and feel if there is one, otherwise
the name of the default cross platform LookAndFeel
class. This value can be overriden by setting the
swing.systemlaf
system property.
String
of the LookAndFeel
classpublic static ComponentUI getUI(JComponent target)
target
- the JComponent
to return the
{@code ComponentUI} forComponentUI
object for {@code target}public static void installLookAndFeel(String name, String className)
name
- descriptive name of the look and feelclassName
- name of the class that implements the look and feelpublic static void installLookAndFeel(UIManager.LookAndFeelInfo info)
info
- a LookAndFeelInfo
object that names the
look and feel and identifies the class that implements itpublic static Object put(Object key, Object value)
key
- an Object
specifying the retrieval keyvalue
- the Object
to store; refer to
{@code UIDefaults} for details on how {@code null} is
handledObject
returned by {@link UIDefaults#put}public static boolean removeAuxiliaryLookAndFeel(LookAndFeel laf)
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.
laf
LookAndFeel
was removed from the listpublic static void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
from the listener list.
This removes a PropertyChangeListener
that was registered
for all properties.
listener
- the PropertyChangeListener
to be removedpublic static void setInstalledLookAndFeels(UIManager.LookAndFeelInfo[] infos) throws SecurityException
infos
- set of LookAndFeelInfo
objects specifying
the available look and feelsSecurityException
public static void setLookAndFeel(LookAndFeel newLookAndFeel) throws UnsupportedLookAndFeelException
A value of {@code null} can be used to set the look and feel to {@code null}. As the {@code LookAndFeel} is required for most of Swing to function, setting the {@code LookAndFeel} to {@code null} is strongly discouraged.
This is a JavaBeans bound property.
newLookAndFeel
- {@code LookAndFeel} to installUnsupportedLookAndFeelException
- if
{@code newLookAndFeel} is {@code non-null} and
{@code newLookAndFeel.isSupportedLookAndFeel()} returns
{@code false}public static void setLookAndFeel(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException
className
- a string specifying the name of the class that implements
the look and feelClassNotFoundException
- if the LookAndFeel
class could not be foundInstantiationException
- if a new instance of the class
couldn't be createdIllegalAccessException
- if the class or initializer isn't accessibleUnsupportedLookAndFeelException
- if
lnf.isSupportedLookAndFeel()
is false
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |