javax.swing

Class UIDefaults

public class UIDefaults extends Hashtable<Object,Object>

UIDefaults is a database where all settings and interface bindings are stored into. A PLAF implementation fills one of these (see for example plaf/basic/BasicLookAndFeel.java) with "ButtonUI" -> new BasicButtonUI().
Nested Class Summary
static interfaceUIDefaults.ActiveValue
Used for lazy instantiation of UIDefaults values so that they are not all loaded when a Swing application starts up, but only the values that are really needed.
static classUIDefaults.LazyInputMap
static interfaceUIDefaults.LazyValue
Used for lazy instantiation of UIDefaults values so that they are not all loaded when a Swing application starts up, but only the values that are really needed.
static classUIDefaults.ProxyLazyValue
Constructor Summary
UIDefaults()
Constructs a new empty UIDefaults instance.
UIDefaults(Object[] entries)
Constructs a new UIDefaults instance and loads the specified entries.
Method Summary
voidaddPropertyChangeListener(PropertyChangeListener listener)
Adds a {@link PropertyChangeListener} to this UIDefaults map.
voidaddResourceBundle(String name)
Adds a ResourceBundle for localized values.
protected voidfirePropertyChange(String property, Object oldValue, Object newValue)
Fires a PropertyChangeEvent.
Objectget(Object key)
Returns the entry for the specified key in the default locale.
Objectget(Object key, Locale loc)
Returns the entry for the specified key in the Locale loc.
booleangetBoolean(Object key)
Returns a boolean entry for the default locale.
booleangetBoolean(Object key, Locale locale)
Returns a boolean entry for a specic locale.
BordergetBorder(Object key)
Returns a border entry for the default locale.
BordergetBorder(Object key, Locale locale)
Returns a border entry for a specic locale.
ColorgetColor(Object key)
Returns a color entry for the default locale.
ColorgetColor(Object key, Locale locale)
Returns a color entry for a specic locale.
LocalegetDefaultLocale()
Returns the current default locale.
DimensiongetDimension(Object key)
Returns a dimension entry for the default locale.
DimensiongetDimension(Object key, Locale locale)
Returns a dimension entry for a specic locale.
FontgetFont(Object key)
Returns a font entry for the default locale.
FontgetFont(Object key, Locale locale)
Returns a font entry for a specic locale.
IcongetIcon(Object key)
Returns an icon entry for the default locale.
IcongetIcon(Object key, Locale locale)
Returns an icon entry for a specic locale.
InsetsgetInsets(Object key)
Returns an insets entry for the default locale.
InsetsgetInsets(Object key, Locale locale)
Returns an insets entry for a specic locale.
intgetInt(Object key)
Returns an integer entry for the default locale.
intgetInt(Object key, Locale locale)
Returns an integer entry for a specic locale.
PropertyChangeListener[]getPropertyChangeListeners()
Returns an array of all registered PropertyChangeListeners.
StringgetString(Object key)
Returns a string entry for the default locale.
StringgetString(Object key, Locale locale)
Returns a string entry for a specic locale.
ComponentUIgetUI(JComponent target)
Returns the {@link ComponentUI} for the specified {@link JComponent}.
Class<? extends ComponentUI>getUIClass(String id, ClassLoader loader)
Returns the ComponentUI class that renders a component.
Class<? extends ComponentUI>getUIClass(String id)
Returns the ComponentUI class that renders a component.
protected voidgetUIError(String msg)
If a key is requested in #get(key) that has no value, this method is called before returning null.
Objectput(Object key, Object value)
Puts a key and value into this UIDefaults object.
In contrast to {@link java.util.Hashtable}s null-values are accepted here and treated like #remove(key).
voidputDefaults(Object[] entries)
Puts a set of key-value pairs into the map.
voidremovePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from this UIDefaults map.
voidremoveResourceBundle(String name)
Removes a ResourceBundle.
voidsetDefaultLocale(Locale loc)
Sets the current locale to loc.

Constructor Detail

UIDefaults

public UIDefaults()
Constructs a new empty UIDefaults instance.

UIDefaults

public UIDefaults(Object[] entries)
Constructs a new UIDefaults instance and loads the specified entries. The entries are expected to come in pairs, that means entries[0] is a key, entries[1] is a value, entries[2] a key and so forth.

Parameters: entries the entries to initialize the UIDefaults instance with

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a {@link PropertyChangeListener} to this UIDefaults map. Registered PropertyChangeListener are notified when values are beeing put into this UIDefaults map.

Parameters: listener the PropertyChangeListener to add

addResourceBundle

public void addResourceBundle(String name)
Adds a ResourceBundle for localized values.

Parameters: name the name of the ResourceBundle to add

firePropertyChange

protected void firePropertyChange(String property, Object oldValue, Object newValue)
Fires a PropertyChangeEvent.

Parameters: property the property name oldValue the old value newValue the new value

get

public Object get(Object key)
Returns the entry for the specified key in the default locale.

Returns: the entry for the specified key

get

public Object get(Object key, Locale loc)
Returns the entry for the specified key in the Locale loc.

Parameters: key the key for which we return the value loc the locale

getBoolean

public boolean getBoolean(Object key)
Returns a boolean entry for the default locale.

Parameters: key the key to the requested entry

Returns: The boolean entry for key or false if no such entry exists.

getBoolean

public boolean getBoolean(Object key, Locale locale)
Returns a boolean entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the boolean entry for key or null if no such entry exists

getBorder

public Border getBorder(Object key)
Returns a border entry for the default locale.

Parameters: key the key to the requested entry

Returns: the border entry for key or null if no such entry exists

getBorder

public Border getBorder(Object key, Locale locale)
Returns a border entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the border entry for key or null if no such entry exists

getColor

public Color getColor(Object key)
Returns a color entry for the default locale.

Parameters: key the key to the requested entry

Returns: the color entry for key or null if no such entry exists

getColor

public Color getColor(Object key, Locale locale)
Returns a color entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the color entry for key or null if no such entry exists

getDefaultLocale

public Locale getDefaultLocale()
Returns the current default locale.

Returns: the current default locale

getDimension

public Dimension getDimension(Object key)
Returns a dimension entry for the default locale.

Parameters: key the key to the requested entry

Returns: the dimension entry for key or null if no such entry exists

getDimension

public Dimension getDimension(Object key, Locale locale)
Returns a dimension entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the boolean entry for key or null if no such entry exists

getFont

public Font getFont(Object key)
Returns a font entry for the default locale.

Parameters: key the key to the requested entry

Returns: the font entry for key or null if no such entry exists

getFont

public Font getFont(Object key, Locale locale)
Returns a font entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the font entry for key or null if no such entry exists

getIcon

public Icon getIcon(Object key)
Returns an icon entry for the default locale.

Parameters: key the key to the requested entry

Returns: the icon entry for key or null if no such entry exists

getIcon

public Icon getIcon(Object key, Locale locale)
Returns an icon entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the icon entry for key or null if no such entry exists

getInsets

public Insets getInsets(Object key)
Returns an insets entry for the default locale.

Parameters: key the key to the requested entry

Returns: the insets entry for key or null if no such entry exists

getInsets

public Insets getInsets(Object key, Locale locale)
Returns an insets entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the boolean entry for key or null if no such entry exists

getInt

public int getInt(Object key)
Returns an integer entry for the default locale.

Parameters: key the key to the requested entry

Returns: the integer entry for key or null if no such entry exists

getInt

public int getInt(Object key, Locale locale)
Returns an integer entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the integer entry for key or null if no such entry exists

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all registered PropertyChangeListeners.

Returns: all registered PropertyChangeListeners

getString

public String getString(Object key)
Returns a string entry for the default locale.

Parameters: key the key to the requested entry

Returns: the string entry for key or null if no such entry exists

getString

public String getString(Object key, Locale locale)
Returns a string entry for a specic locale.

Parameters: key the key to the requested entry locale the locale to the requested entry

Returns: the string entry for key or null if no such entry exists

getUI

public ComponentUI getUI(JComponent target)
Returns the {@link ComponentUI} for the specified {@link JComponent}.

Parameters: target the component for which the ComponentUI is requested

Returns: the {@link ComponentUI} for the specified {@link JComponent}

getUIClass

public Class<? extends ComponentUI> getUIClass(String id, ClassLoader loader)
Returns the ComponentUI class that renders a component. id is the ID for which the String value of the classname is stored in this UIDefaults map.

Parameters: id the ID of the UI class loader the ClassLoader to use

Returns: the UI class for id

getUIClass

public Class<? extends ComponentUI> getUIClass(String id)
Returns the ComponentUI class that renders a component. id is the ID for which the String value of the classname is stored in this UIDefaults map.

Parameters: id the ID of the UI class

Returns: the UI class for id

getUIError

protected void getUIError(String msg)
If a key is requested in #get(key) that has no value, this method is called before returning null.

Parameters: msg the error message

put

public Object put(Object key, Object value)
Puts a key and value into this UIDefaults object.
In contrast to {@link java.util.Hashtable}s null-values are accepted here and treated like #remove(key).
This fires a PropertyChangeEvent with key as name and the old and new values.

Parameters: key the key to put into the map value the value to put into the map

Returns: the old value for key or null if key had no value assigned

putDefaults

public void putDefaults(Object[] entries)
Puts a set of key-value pairs into the map. The entries are expected to come in pairs, that means entries[0] is a key, entries[1] is a value, entries[2] a key and so forth.
If a value is null it is treated like #remove(key).
This unconditionally fires a PropertyChangeEvent with 'UIDefaults' as name and null for old and new value.

Parameters: entries the entries to be put into the map

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from this UIDefaults map.

Parameters: listener the PropertyChangeListener to remove

removeResourceBundle

public void removeResourceBundle(String name)
Removes a ResourceBundle.

Parameters: name the name of the ResourceBundle to remove

setDefaultLocale

public void setDefaultLocale(Locale loc)
Sets the current locale to loc.

Parameters: loc the Locale to be set