Class UIDefaults
- All Implemented Interfaces:
-
Serializable,Cloneable,Map<Object,Object>
public class UIDefaults extends Hashtable<Object,Object>
UIManager. 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 JavaBeans has been added to the java.beans package. Please see XMLEncoder.
- Since:
- 1.2
- See Also:
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
static interface |
UIDefaults.ActiveValue |
This class enables one to store an entry in the defaults table that's constructed each time it's looked up with one of the getXXX(key) methods. |
static class |
UIDefaults.LazyInputMap |
LazyInputMap will create a InputMap in its createValue method. |
static interface |
UIDefaults.LazyValue |
This class enables one to store an entry in the defaults table that isn't constructed until the first time it's looked up with one of the getXXX(key) methods. |
static class |
UIDefaults.ProxyLazyValue |
This class provides an implementation of LazyValue which can be used to delay loading of the Class for the instance to be created. |
Constructor Summary
| Constructor | Description |
|---|---|
UIDefaults() |
Creates an empty defaults table. |
UIDefaults |
Creates an empty defaults table with the specified initial capacity and load factor. |
UIDefaults |
Creates a defaults table initialized with the specified key/value pairs. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
void |
addPropertyChangeListener |
Adds a PropertyChangeListener to the listener list. |
void |
addResourceBundle |
Adds a resource bundle to the list of resource bundles that are searched for localized values. |
protected void |
firePropertyChange |
Support for reporting bound property changes. |
Object |
get |
Returns the value for key. |
Object |
get |
Returns the value for key associated with the given locale. |
boolean |
getBoolean |
If the value of key is boolean, return the boolean value, otherwise return false. |
boolean |
getBoolean |
If the value of key for the given Locale is boolean, return the boolean value, otherwise return false. |
Border |
getBorder |
If the value of key is a Border return it, otherwise return null. |
Border |
getBorder |
If the value of key for the given Locale is a Border return it, otherwise return null. |
Color |
getColor |
If the value of key is a Color return it, otherwise return null. |
Color |
getColor |
If the value of key for the given Locale is a Color return it, otherwise return null. |
Locale |
getDefaultLocale() |
Returns the default locale. |
Dimension |
getDimension |
If the value of key is a Dimension return it, otherwise return null. |
Dimension |
getDimension |
If the value of key for the given Locale is a Dimension return it, otherwise return null. |
Font |
getFont |
If the value of key is a Font return it, otherwise return null. |
Font |
getFont |
If the value of key for the given Locale is a Font return it, otherwise return null. |
Icon |
getIcon |
If the value of key is an Icon return it, otherwise return null. |
Icon |
getIcon |
If the value of key for the given Locale is an Icon return it, otherwise return null. |
Insets |
getInsets |
If the value of key is an Insets return it, otherwise return null. |
Insets |
getInsets |
If the value of key for the given Locale is an Insets return it, otherwise return null. |
int |
getInt |
If the value of key is an Integer return its integer value, otherwise return 0. |
int |
getInt |
If the value of key for the given Locale is an Integer return its integer value, otherwise return 0. |
PropertyChangeListener[] |
getPropertyChangeListeners() |
Returns an array of all the PropertyChangeListeners added to this UIDefaults with addPropertyChangeListener(). |
String |
getString |
If the value of key is a String return it, otherwise return null. |
String |
getString |
If the value of key for the given Locale is a String return it, otherwise return null. |
ComponentUI |
getUI |
Creates an ComponentUI implementation for the specified component. |
Class<? extends ComponentUI> |
getUIClass |
Returns the L&F class that renders this component. |
Class<? extends ComponentUI> |
getUIClass |
The value of get(uidClassID) must be the String name of a class that implements the corresponding ComponentUI class. |
protected void |
getUIError |
If getUI() fails for any reason, it calls this method before returning null. |
Object |
put |
Sets the value of key to value for all locales. |
void |
putDefaults |
Puts all of the key/value pairs in the database and unconditionally generates one PropertyChangeEvent. |
void |
removePropertyChangeListener |
Removes a PropertyChangeListener from the listener list. |
void |
removeResourceBundle |
Removes a resource bundle from the list of resource bundles that are searched for localized defaults. |
void |
setDefaultLocale |
Sets the default locale. |
Methods declared in class java.util.Hashtable
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, hashCode, isEmpty, keys, keySet, merge, putAll, rehash, remove, size, toString, values
Methods declared in interface java.util.Map
forEach, getOrDefault, putIfAbsent, remove, replace, replace, replaceAll
Constructor Details
UIDefaults
public UIDefaults()
UIDefaults
public UIDefaults(int initialCapacity, float loadFactor)
- Parameters:
-
initialCapacity- the initial capacity of the defaults table -
loadFactor- the load factor of the defaults table - Since:
- 1.6
- See Also:
UIDefaults
public UIDefaults(Object[] keyValueList)
Object[] uiDefaults = {
"Font", new Font("Dialog", Font.BOLD, 12),
"Color", Color.red,
"five", Integer.valueOf(5)
}
UIDefaults myDefaults = new UIDefaults(uiDefaults);
- Parameters:
-
keyValueList- an array of objects containing the key/value pairs
Method Details
get
public Object get(Object key)
UIDefaults.LazyValue then the real value is computed with LazyValue.createValue(), the table entry is replaced, and the real value is returned. If the value is an UIDefaults.ActiveValue the table entry is not replaced - the value is computed with ActiveValue.createValue() for each get() call. If the key is not found in the table then it is searched for in the list of resource bundles maintained by this object. The resource bundles are searched most recently added first using the locale returned by getDefaultLocale. LazyValues and ActiveValues are not supported in the resource bundles.get
public Object get(Object key, Locale l)
UIDefaults.LazyValue then the real value is computed with LazyValue.createValue(), the table entry is replaced, and the real value is returned. If the value is an UIDefaults.ActiveValue the table entry is not replaced - the value is computed with ActiveValue.createValue() for each get() call. If the key is not found in the table then it is searched for in the list of resource bundles maintained by this object. The resource bundles are searched most recently added first using the given locale. LazyValues and ActiveValues are not supported in the resource bundles.- Parameters:
-
key- the desired key -
l- the desiredlocale - Returns:
- the value for
key - Since:
- 1.4
- See Also:
put
public Object put(Object key, Object value)
key to value for all locales. If key is a string and the new value isn't equal to the old one, fire a PropertyChangeEvent. If value is null, the key is removed from the table.- Specified by:
-
putin interfaceMap<Object,Object> - Overrides:
-
putin classHashtable<Object,Object> - Parameters:
-
key- the uniqueObjectwho's value will be used to retrieve the data value associated with it -
value- the newObjectto store as data under that key - Returns:
- the previous
Objectvalue, ornull - See Also:
putDefaults
public void putDefaults(Object[] keyValueList)
PropertyChangeEvent. The events oldValue and newValue will be null and its propertyName will be "UIDefaults". The key/value pairs are added for all locales.- Parameters:
-
keyValueList- an array of key/value pairs - See Also:
getFont
public Font getFont(Object key)
key is a Font return it, otherwise return null.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis aFont, return theFontobject; otherwise returnnull
getFont
public Font getFont(Object key, Locale l)
key for the given Locale is a Font return it, otherwise return null.- Parameters:
-
key- the desired key -
l- the desired locale - Returns:
- if the value for
keyandLocaleis aFont, return theFontobject; otherwise returnnull - Since:
- 1.4
getColor
public Color getColor(Object key)
key is a Color return it, otherwise return null.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis aColor, return theColorobject; otherwise returnnull
getColor
public Color getColor(Object key, Locale l)
key for the given Locale is a Color return it, otherwise return null.- Parameters:
-
key- the desired key -
l- the desired locale - Returns:
- if the value for
keyandLocaleis aColor, return theColorobject; otherwise returnnull - Since:
- 1.4
getIcon
public Icon getIcon(Object key)
key is an Icon return it, otherwise return null.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis anIcon, return theIconobject; otherwise returnnull
getIcon
public Icon getIcon(Object key, Locale l)
key for the given Locale is an Icon return it, otherwise return null.- Parameters:
-
key- the desired key -
l- the desired locale - Returns:
- if the value for
keyandLocaleis anIcon, return theIconobject; otherwise returnnull - Since:
- 1.4
getBorder
public Border getBorder(Object key)
key is a Border return it, otherwise return null.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis aBorder, return theBorderobject; otherwise returnnull
getBorder
public Border getBorder(Object key, Locale l)
key for the given Locale is a Border return it, otherwise return null.- Parameters:
-
key- the desired key -
l- the desired locale - Returns:
- if the value for
keyandLocaleis aBorder, return theBorderobject; otherwise returnnull - Since:
- 1.4
getString
public String getString(Object key)
key is a String return it, otherwise return null.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis aString, return theStringobject; otherwise returnnull
getString
public String getString(Object key, Locale l)
key for the given Locale is a String return it, otherwise return null.- Parameters:
-
key- the desired key -
l- the desiredLocale - Returns:
- if the value for
keyfor the givenLocaleis aString, return theStringobject; otherwise returnnull - Since:
- 1.4
getInt
public int getInt(Object key)
key is an Integer return its integer value, otherwise return 0.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis anInteger, return its value, otherwise return 0
getInt
public int getInt(Object key, Locale l)
key for the given Locale is an Integer return its integer value, otherwise return 0.- Parameters:
-
key- the desired key -
l- the desired locale - Returns:
- if the value for
keyandLocaleis anInteger, return its value, otherwise return 0 - Since:
- 1.4
getBoolean
public boolean getBoolean(Object key)
key is boolean, return the boolean value, otherwise return false.- Parameters:
-
key- anObjectspecifying the key for the desired boolean value - Returns:
- if the value of
keyis boolean, return the boolean value, otherwise return false. - Since:
- 1.4
getBoolean
public boolean getBoolean(Object key, Locale l)
key for the given Locale is boolean, return the boolean value, otherwise return false.- Parameters:
-
key- anObjectspecifying the key for the desired boolean value -
l- the desired locale - Returns:
- if the value for
keyandLocaleis boolean, return the boolean value, otherwise return false. - Since:
- 1.4
getInsets
public Insets getInsets(Object key)
key is an Insets return it, otherwise return null.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis anInsets, return theInsetsobject; otherwise returnnull
getInsets
public Insets getInsets(Object key, Locale l)
key for the given Locale is an Insets return it, otherwise return null.- Parameters:
-
key- the desired key -
l- the desired locale - Returns:
- if the value for
keyandLocaleis anInsets, return theInsetsobject; otherwise returnnull - Since:
- 1.4
getDimension
public Dimension getDimension(Object key)
key is a Dimension return it, otherwise return null.- Parameters:
-
key- the desired key - Returns:
- if the value for
keyis aDimension, return theDimensionobject; otherwise returnnull
getDimension
public Dimension getDimension(Object key, Locale l)
key for the given Locale is a Dimension return it, otherwise return null.- Parameters:
-
key- the desired key -
l- the desired locale - Returns:
- if the value for
keyandLocaleis aDimension, return theDimensionobject; otherwise returnnull - Since:
- 1.4
getUIClass
public Class<? extends ComponentUI> getUIClass(String uiClassID, ClassLoader uiClassLoader)
get(uidClassID) must be the String name of a class that implements the corresponding ComponentUI class. If the class hasn't been loaded before, this method looks up the class with uiClassLoader.loadClass() if a non null class loader is provided, classForName() otherwise. If a mapping for uiClassID exists or if the specified class can't be found, return null.
This method is used by getUI, it's usually not necessary to call it directly.
- Parameters:
-
uiClassID- a string containing the class ID -
uiClassLoader- the object which will load the class - Returns:
- the value of
Class.forName(get(uidClassID)) - See Also:
getUIClass
public Class<? extends ComponentUI> getUIClass(String uiClassID)
- Parameters:
-
uiClassID- a string containing the class ID - Returns:
- the Class object returned by
getUIClass(uiClassID, null)
getUIError
protected void getUIError(String msg)
getUI() fails for any reason, it calls this method before returning null. Subclasses may choose to do more or less here.- Parameters:
-
msg- message string to print - See Also:
getUI
public ComponentUI getUI(JComponent target)
ComponentUI implementation for the specified component. In other words create the look and feel specific delegate object for target. This is done in two steps: - Look up the name of the
ComponentUIimplementation class under the value returned bytarget.getUIClassID(). - Use the implementation classes static
createUI()method to construct a look and feel delegate.
- Parameters:
-
target- theJComponentwhich needs a UI - Returns:
- the
ComponentUIobject
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener to the listener list. The listener is registered for all properties. A PropertyChangeEvent will get fired whenever a default is changed.
- Parameters:
-
listener- thePropertyChangeListenerto be added - See Also:
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.- Parameters:
-
listener- thePropertyChangeListenerto be removed - See Also:
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListeners added to this UIDefaults with addPropertyChangeListener().- Returns:
- all of the
PropertyChangeListeners added or an empty array if no listeners have been added - Since:
- 1.4
firePropertyChange
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
PropertyChangeEventx listener list isn't empty, then fire a PropertyChange event to each listener.- Parameters:
-
propertyName- the programmatic name of the property that was changed -
oldValue- the old value of the property -
newValue- the new value of the property - See Also:
addResourceBundle
public void addResourceBundle(String bundleName)
- Parameters:
-
bundleName- the base name of the resource bundle to be added - Since:
- 1.4
- See Also:
removeResourceBundle
public void removeResourceBundle(String bundleName)
- Parameters:
-
bundleName- the base name of the resource bundle to be removed - Since:
- 1.4
- See Also:
setDefaultLocale
public void setDefaultLocale(Locale l)
get methods that do not take a locale argument. As of release 1.4, Swing UI objects should retrieve localized values using the locale of their component rather than the default locale. The default locale exists to provide compatibility with pre 1.4 behaviour.- Parameters:
-
l- the new default locale - Since:
- 1.4
- See Also:
getDefaultLocale
public Locale getDefaultLocale()
get methods that do not take a locale argument. As of release 1.4, Swing UI objects should retrieve localized values using the locale of their component rather than the default locale. The default locale exists to provide compatibility with pre 1.4 behaviour.- Returns:
- the default locale
- Since:
- 1.4
- See Also:
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/UIDefaults.html