UIDefaults (Java SE 15 & JDK 15) (original) (raw)
All Implemented Interfaces:
[Serializable](../../../java.base/java/io/Serializable.html "interface in java.io")
, [Cloneable](../../../java.base/java/lang/Cloneable.html "interface in java.lang")
, [Map](../../../java.base/java/util/Map.html "interface in java.util")<[Object](../../../java.base/java/lang/Object.html "class in java.lang"),[Object](../../../java.base/java/lang/Object.html "class in java.lang")>
public class UIDefaults extends Hashtable<Object,Object>
A table of defaults for Swing components. Applications can set/get default values via the 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
Nested Classes
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
Constructors
Constructor | Description |
---|---|
UIDefaults() | Creates an empty defaults table. |
UIDefaults(int initialCapacity, float loadFactor) | Creates an empty defaults table with the specified initial capacity and load factor. |
UIDefaults(Object[] keyValueList) | Creates a defaults table initialized with the specified key/value pairs. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
void | addPropertyChangeListener(PropertyChangeListener listener) | Adds a PropertyChangeListener to the listener list. |
void | addResourceBundle(String bundleName) | Adds a resource bundle to the list of resource bundles that are searched for localized values. |
protected void | firePropertyChange(String propertyName,Object oldValue,Object newValue) | Support for reporting bound property changes. |
Object | get(Object key) | Returns the value for key. |
Object | get(Object key,Locale l) | Returns the value for key associated with the given locale. |
boolean | getBoolean(Object key) | If the value of key is boolean, return the boolean value, otherwise return false. |
boolean | getBoolean(Object key,Locale l) | If the value of key for the given Locale is boolean, return the boolean value, otherwise return false. |
Border | getBorder(Object key) | If the value of key is a Border return it, otherwise return null. |
Border | getBorder(Object key,Locale l) | If the value of key for the given Locale is a Border return it, otherwise return null. |
Color | getColor(Object key) | If the value of key is a Color return it, otherwise return null. |
Color | getColor(Object key,Locale l) | 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(Object key) | If the value of key is a Dimension return it, otherwise return null. |
Dimension | getDimension(Object key,Locale l) | If the value of key for the given Locale is a Dimension return it, otherwise return null. |
Font | getFont(Object key) | If the value of key is a Font return it, otherwise return null. |
Font | getFont(Object key,Locale l) | If the value of key for the given Locale is a Font return it, otherwise return null. |
Icon | getIcon(Object key) | If the value of key is an Icon return it, otherwise return null. |
Icon | getIcon(Object key,Locale l) | If the value of key for the given Locale is an Icon return it, otherwise return null. |
Insets | getInsets(Object key) | If the value of key is an Insets return it, otherwise return null. |
Insets | getInsets(Object key,Locale l) | If the value of key for the given Locale is an Insets return it, otherwise return null. |
int | getInt(Object key) | If the value of key is an Integer return its integer value, otherwise return 0. |
int | getInt(Object key,Locale l) | 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(Object key) | If the value of key is a String return it, otherwise return null. |
String | getString(Object key,Locale l) | If the value of key for the given Locale is a String return it, otherwise return null. |
ComponentUI | getUI(JComponent target) | Creates an ComponentUI implementation for the specified component. |
Class<? extends ComponentUI> | getUIClass(String uiClassID) | Returns the L&F class that renders this component. |
Class<? extends ComponentUI> | getUIClass(String uiClassID,ClassLoader uiClassLoader) | The value of get(uidClassID) must be theString name of a class that implements the corresponding ComponentUI class. |
protected void | getUIError(String msg) | If getUI() fails for any reason, it calls this method before returning null. |
Object | put(Object key,Object value) | Sets the value of key to value for all locales. |
void | putDefaults(Object[] keyValueList) | Puts all of the key/value pairs in the database and unconditionally generates one PropertyChangeEvent. |
void | removePropertyChangeListener(PropertyChangeListener listener) | Removes a PropertyChangeListener from the listener list. |
void | removeResourceBundle(String bundleName) | Removes a resource bundle from the list of resource bundles that are searched for localized defaults. |
void | setDefaultLocale(Locale l) | Sets the default locale. |
Methods declared in class java.util.Hashtable
[clear](../../../java.base/java/util/Hashtable.html#clear%28%29), [clone](../../../java.base/java/util/Hashtable.html#clone%28%29), [compute](../../../java.base/java/util/Hashtable.html#compute%28K,java.util.function.BiFunction%29), [computeIfAbsent](../../../java.base/java/util/Hashtable.html#computeIfAbsent%28K,java.util.function.Function%29), [computeIfPresent](../../../java.base/java/util/Hashtable.html#computeIfPresent%28K,java.util.function.BiFunction%29), [contains](../../../java.base/java/util/Hashtable.html#contains%28java.lang.Object%29), [containsKey](../../../java.base/java/util/Hashtable.html#containsKey%28java.lang.Object%29), [containsValue](../../../java.base/java/util/Hashtable.html#containsValue%28java.lang.Object%29), [elements](../../../java.base/java/util/Hashtable.html#elements%28%29), [entrySet](../../../java.base/java/util/Hashtable.html#entrySet%28%29), [equals](../../../java.base/java/util/Hashtable.html#equals%28java.lang.Object%29), [hashCode](../../../java.base/java/util/Hashtable.html#hashCode%28%29), [isEmpty](../../../java.base/java/util/Hashtable.html#isEmpty%28%29), [keys](../../../java.base/java/util/Hashtable.html#keys%28%29), [keySet](../../../java.base/java/util/Hashtable.html#keySet%28%29), [merge](../../../java.base/java/util/Hashtable.html#merge%28K,V,java.util.function.BiFunction%29), [putAll](../../../java.base/java/util/Hashtable.html#putAll%28java.util.Map%29), [rehash](../../../java.base/java/util/Hashtable.html#rehash%28%29), [remove](../../../java.base/java/util/Hashtable.html#remove%28java.lang.Object%29), [size](../../../java.base/java/util/Hashtable.html#size%28%29), [toString](../../../java.base/java/util/Hashtable.html#toString%28%29), [values](../../../java.base/java/util/Hashtable.html#values%28%29)
Constructor Details
UIDefaults
public UIDefaults()
Creates an empty defaults table.UIDefaults
public UIDefaults(int initialCapacity, float loadFactor)
Creates an empty defaults table with the specified initial capacity and load factor.
Parameters:
initialCapacity
- the initial capacity of the defaults table
loadFactor
- the load factor of the defaults table
Since:
1.6
See Also:
HashtableUIDefaults
public UIDefaults(Object[] keyValueList)
Creates a defaults table initialized with the specified key/value pairs. For example:
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 pairsMethod Details
get
Returns the value for key. If the value is a
UIDefaults.LazyValue
then the real value is computed withLazyValue.createValue()
, the table entry is replaced, and the real value is returned. If the value is anUIDefaults.ActiveValue
the table entry is not replaced - the value is computed withActiveValue.createValue()
for eachget()
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 bygetDefaultLocale
.LazyValues
andActiveValues
are not supported in the resource bundles.
Specified by:
[get](../../../java.base/java/util/Map.html#get%28java.lang.Object%29)
in interface[Map](../../../java.base/java/util/Map.html "interface in java.util")<[Object](../../../java.base/java/lang/Object.html "class in java.lang"),[Object](../../../java.base/java/lang/Object.html "class in java.lang")>
Overrides:
[get](../../../java.base/java/util/Hashtable.html#get%28java.lang.Object%29)
in class[Hashtable](../../../java.base/java/util/Hashtable.html "class in java.util")<[Object](../../../java.base/java/lang/Object.html "class in java.lang"),[Object](../../../java.base/java/lang/Object.html "class in java.lang")>
Parameters:
key
- the desired key
Returns:
the value forkey
Since:
1.4
See Also:
UIDefaults.LazyValue, UIDefaults.ActiveValue, Hashtable.get(java.lang.Object), getDefaultLocale(), addResourceBundle(java.lang.String)get
Returns the value for key associated with the given locale. If the value is a
UIDefaults.LazyValue
then the real value is computed withLazyValue.createValue()
, the table entry is replaced, and the real value is returned. If the value is anUIDefaults.ActiveValue
the table entry is not replaced - the value is computed withActiveValue.createValue()
for eachget()
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
andActiveValues
are not supported in the resource bundles.
Parameters:
key
- the desired key
l
- the desiredlocale
Returns:
the value forkey
Since:
1.4
See Also:
UIDefaults.LazyValue, UIDefaults.ActiveValue, Hashtable.get(java.lang.Object), addResourceBundle(java.lang.String)put
Sets the value of
key
tovalue
for all locales. Ifkey
is a string and the new value isn't equal to the old one, fire aPropertyChangeEvent
. If value isnull
, the key is removed from the table.
Specified by:
[put](../../../java.base/java/util/Map.html#put%28K,V%29)
in interface[Map](../../../java.base/java/util/Map.html "interface in java.util")<[Object](../../../java.base/java/lang/Object.html "class in java.lang"),[Object](../../../java.base/java/lang/Object.html "class in java.lang")>
Overrides:
[put](../../../java.base/java/util/Hashtable.html#put%28K,V%29)
in class[Hashtable](../../../java.base/java/util/Hashtable.html "class in java.util")<[Object](../../../java.base/java/lang/Object.html "class in java.lang"),[Object](../../../java.base/java/lang/Object.html "class in java.lang")>
Parameters:
key
- the uniqueObject
who's value will be used to retrieve the data value associated with it
value
- the newObject
to store as data under that key
Returns:
the previousObject
value, ornull
See Also:
putDefaults(java.lang.Object[]), Hashtable.put(K, V)putDefaults
public void putDefaults(Object[] keyValueList)
Puts all of the key/value pairs in the database and unconditionally generates onePropertyChangeEvent
. The events oldValue and newValue will benull
and itspropertyName
will be "UIDefaults". The key/value pairs are added for all locales.
Parameters:
keyValueList
- an array of key/value pairs
See Also:
put(java.lang.Object, java.lang.Object), Hashtable.put(K, V)getFont
If the value of
key
is aFont
return it, otherwise returnnull
.
Parameters:
key
- the desired key
Returns:
if the value forkey
is aFont
, return theFont
object; otherwise returnnull
getFont
If the value of
key
for the givenLocale
is aFont
return it, otherwise returnnull
.
Parameters:
key
- the desired key
l
- the desired locale
Returns:
if the value forkey
andLocale
is aFont
, return theFont
object; otherwise returnnull
Since:
1.4getColor
If the value of
key
is aColor
return it, otherwise returnnull
.
Parameters:
key
- the desired key
Returns:
if the value forkey
is aColor
, return theColor
object; otherwise returnnull
getColor
If the value of
key
for the givenLocale
is aColor
return it, otherwise returnnull
.
Parameters:
key
- the desired key
l
- the desired locale
Returns:
if the value forkey
andLocale
is aColor
, return theColor
object; otherwise returnnull
Since:
1.4getIcon
If the value of
key
is anIcon
return it, otherwise returnnull
.
Parameters:
key
- the desired key
Returns:
if the value forkey
is anIcon
, return theIcon
object; otherwise returnnull
getIcon
If the value of
key
for the givenLocale
is anIcon
return it, otherwise returnnull
.
Parameters:
key
- the desired key
l
- the desired locale
Returns:
if the value forkey
andLocale
is anIcon
, return theIcon
object; otherwise returnnull
Since:
1.4getBorder
If the value of
key
is aBorder
return it, otherwise returnnull
.
Parameters:
key
- the desired key
Returns:
if the value forkey
is aBorder
, return theBorder
object; otherwise returnnull
getBorder
If the value of
key
for the givenLocale
is aBorder
return it, otherwise returnnull
.
Parameters:
key
- the desired key
l
- the desired locale
Returns:
if the value forkey
andLocale
is aBorder
, return theBorder
object; otherwise returnnull
Since:
1.4getString
If the value of
key
is aString
return it, otherwise returnnull
.
Parameters:
key
- the desired key
Returns:
if the value forkey
is aString
, return theString
object; otherwise returnnull
getString
If the value of
key
for the givenLocale
is aString
return it, otherwise returnnull
.
Parameters:
key
- the desired key
l
- the desiredLocale
Returns:
if the value forkey
for the givenLocale
is aString
, return theString
object; otherwise returnnull
Since:
1.4getInt
public int getInt(Object key)
If the value ofkey
is anInteger
return its integer value, otherwise return 0.
Parameters:
key
- the desired key
Returns:
if the value forkey
is anInteger
, return its value, otherwise return 0getInt
If the value of
key
for the givenLocale
is anInteger
return its integer value, otherwise return 0.
Parameters:
key
- the desired key
l
- the desired locale
Returns:
if the value forkey
andLocale
is anInteger
, return its value, otherwise return 0
Since:
1.4getBoolean
public boolean getBoolean(Object key)
If the value ofkey
is boolean, return the boolean value, otherwise return false.
Parameters:
key
- anObject
specifying the key for the desired boolean value
Returns:
if the value ofkey
is boolean, return the boolean value, otherwise return false.
Since:
1.4getBoolean
If the value of
key
for the givenLocale
is boolean, return the boolean value, otherwise return false.
Parameters:
key
- anObject
specifying the key for the desired boolean value
l
- the desired locale
Returns:
if the value forkey
andLocale
is boolean, return the boolean value, otherwise return false.
Since:
1.4getInsets
If the value of
key
is anInsets
return it, otherwise returnnull
.
Parameters:
key
- the desired key
Returns:
if the value forkey
is anInsets
, return theInsets
object; otherwise returnnull
getInsets
If the value of
key
for the givenLocale
is anInsets
return it, otherwise returnnull
.
Parameters:
key
- the desired key
l
- the desired locale
Returns:
if the value forkey
andLocale
is anInsets
, return theInsets
object; otherwise returnnull
Since:
1.4getDimension
If the value of
key
is aDimension
return it, otherwise returnnull
.
Parameters:
key
- the desired key
Returns:
if the value forkey
is aDimension
, return theDimension
object; otherwise returnnull
getDimension
If the value of
key
for the givenLocale
is aDimension
return it, otherwise returnnull
.
Parameters:
key
- the desired key
l
- the desired locale
Returns:
if the value forkey
andLocale
is aDimension
, return theDimension
object; otherwise returnnull
Since:
1.4getUIClass
The value of
get(uidClassID)
must be theString
name of a class that implements the correspondingComponentUI
class. If the class hasn't been loaded before, this method looks up the class withuiClassLoader.loadClass()
if a nonnull
class loader is provided,classForName()
otherwise.
If a mapping foruiClassID
exists or if the specified class can't be found, returnnull
.
This method is used bygetUI
, 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 ofClass.forName(get(uidClassID))
See Also:
getUI(javax.swing.JComponent)getUIClass
Returns the L&F class that renders this component.
Parameters:
uiClassID
- a string containing the class ID
Returns:
the Class object returned bygetUIClass(uiClassID, null)
getUIError
protected void getUIError(String msg)
IfgetUI()
fails for any reason, it calls this method before returningnull
. Subclasses may choose to do more or less here.
Parameters:
msg
- message string to print
See Also:
getUI(javax.swing.JComponent)getUI
Creates an
ComponentUI
implementation for the specified component. In other words create the look and feel specific delegate object fortarget
. This is done in two steps:
* Look up the name of theComponentUI
implementation class under the value returned bytarget.getUIClassID()
.
* Use the implementation classes staticcreateUI()
method to construct a look and feel delegate.
Parameters:
target
- theJComponent
which needs a UI
Returns:
theComponentUI
objectaddPropertyChangeListener
Adds a
PropertyChangeListener
to the listener list. The listener is registered for all properties.
APropertyChangeEvent
will get fired whenever a default is changed.
Parameters:
listener
- thePropertyChangeListener
to be added
See Also:
PropertyChangeSupportremovePropertyChangeListener
Removes a
PropertyChangeListener
from the listener list. This removes aPropertyChangeListener
that was registered for all properties.
Parameters:
listener
- thePropertyChangeListener
to be removed
See Also:
PropertyChangeSupportgetPropertyChangeListeners
Returns an array of all the
PropertyChangeListener
s added to this UIDefaults with addPropertyChangeListener().
Returns:
all of thePropertyChangeListener
s added or an empty array if no listeners have been added
Since:
1.4firePropertyChange
protected void firePropertyChange(String propertyName,Object oldValue,Object newValue)
Support for reporting bound property changes. If oldValue and newValue are not equal and thePropertyChangeEvent
x listener list isn't empty, then fire aPropertyChange
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:
PropertyChangeSupportaddResourceBundle
public void addResourceBundle(String bundleName)
Adds a resource bundle to the list of resource bundles that are searched for localized values. Resource bundles are searched in the reverse order they were added, using thesystem class loader. In other words, the most recently added bundle is searched first.
Parameters:
bundleName
- the base name of the resource bundle to be added
Since:
1.4
See Also:
ResourceBundle, removeResourceBundle(java.lang.String), ResourceBundle.getBundle(String, Locale, ClassLoader)removeResourceBundle
public void removeResourceBundle(String bundleName)
Removes a resource bundle from the list of resource bundles that are searched for localized defaults.
Parameters:
bundleName
- the base name of the resource bundle to be removed
Since:
1.4
See Also:
ResourceBundle, addResourceBundle(java.lang.String)setDefaultLocale
public void setDefaultLocale(Locale l)
Sets the default locale. The default locale is used in retrieving localized values viaget
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(), get(Object), get(Object,Locale)getDefaultLocale
public Locale getDefaultLocale()
Returns the default locale. The default locale is used in retrieving localized values viaget
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:
setDefaultLocale(java.util.Locale), get(Object), get(Object,Locale)