Class UIDefaults
- All Implemented Interfaces:
Serializable, Cloneable, Map<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 ClassesModifier and TypeClassDescriptionstatic interfaceThis class enables one to store an entry in the defaults table that's constructed each time it's looked up with one of thegetXXX(key)methods.static classLazyInputMapwill create aInputMapin itscreateValuemethod.static interfaceThis 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 thegetXXX(key)methods.static classThis class provides an implementation ofLazyValuewhich can be used to delay loading of the Class for the instance to be created. -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionvoidAdds aPropertyChangeListenerto the listener list.voidaddResourceBundle(String bundleName) Adds a resource bundle to the list of resource bundles that are searched for localized values.protected voidfirePropertyChange(String propertyName, Object oldValue, Object newValue) Support for reporting bound property changes.Returns the value for key.Returns the value for key associated with the given locale.booleangetBoolean(Object key) If the value ofkeyis boolean, return the boolean value, otherwise return false.booleangetBoolean(Object key, Locale l) If the value ofkeyfor the givenLocaleis boolean, return the boolean value, otherwise return false.If the value ofkeyis aBorderreturn it, otherwise returnnull.If the value ofkeyfor the givenLocaleis aBorderreturn it, otherwise returnnull.If the value ofkeyis aColorreturn it, otherwise returnnull.If the value ofkeyfor the givenLocaleis aColorreturn it, otherwise returnnull.Returns the default locale.getDimension(Object key) If the value ofkeyis aDimensionreturn it, otherwise returnnull.getDimension(Object key, Locale l) If the value ofkeyfor the givenLocaleis aDimensionreturn it, otherwise returnnull.If the value ofkeyis aFontreturn it, otherwise returnnull.If the value ofkeyfor the givenLocaleis aFontreturn it, otherwise returnnull.If the value ofkeyis anIconreturn it, otherwise returnnull.If the value ofkeyfor the givenLocaleis anIconreturn it, otherwise returnnull.If the value ofkeyis anInsetsreturn it, otherwise returnnull.If the value ofkeyfor the givenLocaleis anInsetsreturn it, otherwise returnnull.intIf the value ofkeyis anIntegerreturn its integer value, otherwise return 0.intIf the value ofkeyfor the givenLocaleis anIntegerreturn its integer value, otherwise return 0.Returns an array of all thePropertyChangeListeners added to this UIDefaults with addPropertyChangeListener().If the value ofkeyis aStringreturn it, otherwise returnnull.If the value ofkeyfor the givenLocaleis aStringreturn it, otherwise returnnull.getUI(JComponent target) Creates anComponentUIimplementation 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 ofget(uidClassID)must be theStringname of a class that implements the correspondingComponentUIclass.protected voidgetUIError(String msg) IfgetUI()fails for any reason, it calls this method before returningnull.Sets the value ofkeytovaluefor all locales.voidputDefaults(Object[] keyValueList) Puts all of the key/value pairs in the database and unconditionally generates onePropertyChangeEvent.voidRemoves aPropertyChangeListenerfrom the listener list.voidremoveResourceBundle(String bundleName) Removes a resource bundle from the list of resource bundles that are searched for localized defaults.voidSets the default locale.Methods declared in class Hashtable
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, hashCode, isEmpty, keys, keySet, merge, putAll, rehash, remove, size, toString, valuesModifier and TypeMethodDescriptionvoidclear()Clears this hashtable so that it contains no keys.clone()Creates a shallow copy of this hashtable.Attempts to compute a mapping for the specified key and its current mapped value, ornullif there is no current mapping (optional operation).computeIfAbsent(Object key, Function<? super Object, ? extends Object> mappingFunction) If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull(optional operation).computeIfPresent(Object key, BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value (optional operation).booleanTests if some key maps into the specified value in this hashtable.booleancontainsKey(Object key) Tests if the specified object is a key in this hashtable.booleancontainsValue(Object value) Returns true if this hashtable maps one or more keys to this value.elements()Returns an enumeration of the values in this hashtable.entrySet()Returns aSetview of the mappings contained in this map.booleanCompares the specified Object with this Map for equality, as per the definition in the Map interface.inthashCode()Returns the hash code value for this Map as per the definition in the Map interface.booleanisEmpty()Tests if this hashtable maps no keys to values.keys()Returns an enumeration of the keys in this hashtable.keySet()Returns aSetview of the keys contained in this map.merge(Object key, Object value, BiFunction<? super Object, ? super Object, ? extends Object> remappingFunction) If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value (optional operation).voidCopies all of the mappings from the specified map to this hashtable.protected voidrehash()Increases the capacity of and internally reorganizes this hashtable, in order to accommodate and access its entries more efficiently.Removes the key (and its corresponding value) from this hashtable.intsize()Returns the number of keys in this hashtable.toString()Returns a string representation of thisHashtableobject in the form of a set of entries, enclosed in braces and separated by the ASCII characters "," (comma and space).values()Returns aCollectionview of the values contained in this map.Methods declared in class Object
finalize, getClass, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization is deprecated and subject to removal in a future release.final Class<?> getClass()Returns the runtime class of thisObject.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.Methods declared in interface Map
forEach, getOrDefault, putIfAbsent, remove, replace, replace, replaceAllModifier and TypeMethodDescriptiondefault voidforEach(BiConsumer<? super Object, ? super Object> action) Performs the given action for each entry in this map until all entries have been processed or the action throws an exception.default ObjectgetOrDefault(Object key, Object defaultValue) Returns the value to which the specified key is mapped, ordefaultValueif this map contains no mapping for the key.default ObjectputIfAbsent(Object key, Object value) If the specified key is not already associated with a value (or is mapped tonull) associates it with the given value and returnsnull, else returns the current value (optional operation).default booleanRemoves the entry for the specified key only if it is currently mapped to the specified value (optional operation).default ObjectReplaces the entry for the specified key only if it is currently mapped to some value (optional operation).default booleanReplaces the entry for the specified key only if currently mapped to the specified value (optional operation).default voidreplaceAll(BiFunction<? super Object, ? super Object, ? extends Object> function) Replaces each entry's value with the result of invoking the given function on that entry until all entries have been processed or the function throws an exception (optional operation).
-
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 tableloadFactor- the load factor of the defaults table- Since:
- 1.6
- See Also:
-
UIDefaults
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 pairs
-
-
Method Details
-
get
Returns the value for key. If the value is aUIDefaults.LazyValuethen the real value is computed withLazyValue.createValue(), the table entry is replaced, and the real value is returned. If the value is anUIDefaults.ActiveValuethe 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.LazyValuesandActiveValuesare not supported in the resource bundles. -
get
Returns the value for key associated with the given locale. If the value is aUIDefaults.LazyValuethen the real value is computed withLazyValue.createValue(), the table entry is replaced, and the real value is returned. If the value is anUIDefaults.ActiveValuethe 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.LazyValuesandActiveValuesare not supported in the resource bundles.- Parameters:
key- the desired keyl- the desiredlocale- Returns:
- the value for
key - Since:
- 1.4
- See Also:
-
put
Sets the value ofkeytovaluefor all locales. Ifkeyis 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:
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 itvalue- the newObjectto store as data under that key- Returns:
- the previous
Objectvalue, ornull - See Also:
-
putDefaults
Puts all of the key/value pairs in the database and unconditionally generates onePropertyChangeEvent. The events oldValue and newValue will benulland itspropertyNamewill be "UIDefaults". The key/value pairs are added for all locales.- Parameters:
keyValueList- an array of key/value pairs- See Also:
-
getFont
-
getFont
-
getColor
-
getColor
-
getIcon
-
getIcon
-
getBorder
-
getBorder
If the value ofkeyfor the givenLocaleis aBorderreturn it, otherwise returnnull.- Parameters:
key- the desired keyl- the desired locale- Returns:
- if the value for
keyandLocaleis aBorder, return theBorderobject; otherwise returnnull - Since:
- 1.4
-
getString
-
getString
If the value ofkeyfor the givenLocaleis aStringreturn it, otherwise returnnull.- Parameters:
key- the desired keyl- the desiredLocale- Returns:
- if the value for
keyfor the givenLocaleis aString, return theStringobject; otherwise returnnull - Since:
- 1.4
-
getInt
If the value ofkeyis anIntegerreturn 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
If the value ofkeyfor the givenLocaleis anIntegerreturn its integer value, otherwise return 0.- Parameters:
key- the desired keyl- the desired locale- Returns:
- if the value for
keyandLocaleis anInteger, return its value, otherwise return 0 - Since:
- 1.4
-
getBoolean
If the value ofkeyis 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
If the value ofkeyfor the givenLocaleis boolean, return the boolean value, otherwise return false.- Parameters:
key- anObjectspecifying the key for the desired boolean valuel- the desired locale- Returns:
- if the value for
keyandLocaleis boolean, return the boolean value, otherwise return false. - Since:
- 1.4
-
getInsets
-
getInsets
If the value ofkeyfor the givenLocaleis anInsetsreturn it, otherwise returnnull.- Parameters:
key- the desired keyl- the desired locale- Returns:
- if the value for
keyandLocaleis anInsets, return theInsetsobject; otherwise returnnull - Since:
- 1.4
-
getDimension
-
getDimension
If the value ofkeyfor the givenLocaleis aDimensionreturn it, otherwise returnnull.- Parameters:
key- the desired keyl- the desired locale- Returns:
- if the value for
keyandLocaleis aDimension, return theDimensionobject; otherwise returnnull - Since:
- 1.4
-
getUIClass
The value ofget(uidClassID)must be theStringname of a class that implements the correspondingComponentUIclass. If the class hasn't been loaded before, this method looks up the class withuiClassLoader.loadClass()if a nonnullclass loader is provided,classForName()otherwise.If a mapping for
uiClassIDexists or if the specified class can't be found, returnnull.This method is used by
getUI, it's usually not necessary to call it directly.- Parameters:
uiClassID- a string containing the class IDuiClassLoader- the object which will load the class- Returns:
- the value of
Class.forName(get(uidClassID)) - See Also:
-
getUIClass
Returns the L&F class that renders this component.- Parameters:
uiClassID- a string containing the class ID- Returns:
- the Class object returned by
getUIClass(uiClassID, null)
-
getUIError
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
Creates anComponentUIimplementation 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 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
- Look up the name of the
-
addPropertyChangeListener
Adds aPropertyChangeListenerto the listener list. The listener is registered for all properties.A
PropertyChangeEventwill get fired whenever a default is changed.- Parameters:
listener- thePropertyChangeListenerto be added- See Also:
-
removePropertyChangeListener
Removes aPropertyChangeListenerfrom the listener list. This removes aPropertyChangeListenerthat was registered for all properties.- Parameters:
listener- thePropertyChangeListenerto be removed- See Also:
-
getPropertyChangeListeners
Returns an array of all thePropertyChangeListeners 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
Support for reporting bound property changes. If oldValue and newValue are not equal and thePropertyChangeEventx listener list isn't empty, then fire aPropertyChangeevent to each listener.- Parameters:
propertyName- the programmatic name of the property that was changedoldValue- the old value of the propertynewValue- the new value of the property- See Also:
-
addResourceBundle
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 the system 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:
-
removeResourceBundle
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:
-
setDefaultLocale
Sets the default locale. The default locale is used in retrieving localized values viagetmethods 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
Returns the default locale. The default locale is used in retrieving localized values viagetmethods 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:
-