- java.lang.Object
- 
- java.util.Dictionary<K,V>
- 
- java.util.Hashtable<Object,Object>
- 
- javax.swing.UIDefaults
 
 
 
- 
- All Implemented Interfaces:
- Serializable,- Cloneable,- Map<Object,Object>
 
 public class UIDefaults extends Hashtable<Object,Object> A table of defaults for Swing components. Applications can set/get default values via theUIManager.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.beanspackage. Please seeXMLEncoder.- Since:
- 1.2
- See Also:
- UIManager, Serialized Form
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static interfaceUIDefaults.ActiveValueThis 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 classUIDefaults.LazyInputMapLazyInputMapwill create aInputMapin itscreateValuemethod.static interfaceUIDefaults.LazyValueThis 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 classUIDefaults.ProxyLazyValueThis class provides an implementation ofLazyValuewhich can be used to delay loading of the Class for the instance to be created.
 - 
Constructor SummaryConstructors 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 SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(PropertyChangeListener listener)Adds 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.Objectget(Object key)Returns the value for key.Objectget(Object key, Locale l)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.BordergetBorder(Object key)If the value ofkeyis aBorderreturn it, otherwise returnnull.BordergetBorder(Object key, Locale l)If the value ofkeyfor the givenLocaleis aBorderreturn it, otherwise returnnull.ColorgetColor(Object key)If the value ofkeyis aColorreturn it, otherwise returnnull.ColorgetColor(Object key, Locale l)If the value ofkeyfor the givenLocaleis aColorreturn it, otherwise returnnull.LocalegetDefaultLocale()Returns the default locale.DimensiongetDimension(Object key)If the value ofkeyis aDimensionreturn it, otherwise returnnull.DimensiongetDimension(Object key, Locale l)If the value ofkeyfor the givenLocaleis aDimensionreturn it, otherwise returnnull.FontgetFont(Object key)If the value ofkeyis aFontreturn it, otherwise returnnull.FontgetFont(Object key, Locale l)If the value ofkeyfor the givenLocaleis aFontreturn it, otherwise returnnull.IcongetIcon(Object key)If the value ofkeyis anIconreturn it, otherwise returnnull.IcongetIcon(Object key, Locale l)If the value ofkeyfor the givenLocaleis anIconreturn it, otherwise returnnull.InsetsgetInsets(Object key)If the value ofkeyis anInsetsreturn it, otherwise returnnull.InsetsgetInsets(Object key, Locale l)If the value ofkeyfor the givenLocaleis anInsetsreturn it, otherwise returnnull.intgetInt(Object key)If the value ofkeyis anIntegerreturn its integer value, otherwise return 0.intgetInt(Object key, Locale l)If the value ofkeyfor the givenLocaleis anIntegerreturn its integer value, otherwise return 0.PropertyChangeListener[]getPropertyChangeListeners()Returns an array of all thePropertyChangeListeners added to this UIDefaults with addPropertyChangeListener().StringgetString(Object key)If the value ofkeyis aStringreturn it, otherwise returnnull.StringgetString(Object key, Locale l)If the value ofkeyfor the givenLocaleis aStringreturn it, otherwise returnnull.ComponentUIgetUI(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.Objectput(Object key, Object value)Sets the value ofkeytovaluefor all locales.voidputDefaults(Object[] keyValueList)Puts all of the key/value pairs in the database and unconditionally generates onePropertyChangeEvent.voidremovePropertyChangeListener(PropertyChangeListener listener)Removes aPropertyChangeListenerfrom the listener list.voidremoveResourceBundle(String bundleName)Removes a resource bundle from the list of resource bundles that are searched for localized defaults.voidsetDefaultLocale(Locale l)Sets the default locale.- 
Methods declared in class java.util.Hashtableclear, 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.MapforEach, getOrDefault, putIfAbsent, remove, replace, replace, replaceAll
 
- 
 
- 
- 
- 
Constructor Detail- 
UIDefaultspublic UIDefaults() Creates an empty defaults table.
 - 
UIDefaultspublic 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:
- Hashtable
 
 - 
UIDefaultspublic 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 pairs
 
 
- 
 - 
Method Detail- 
getpublic Object get(Object key) 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.- Specified by:
- getin interface- Map<Object,Object>
- Overrides:
- getin class- Hashtable<Object,Object>
- Parameters:
- key- the desired key
- Returns:
- the value for key
- Since:
- 1.4
- See Also:
- UIDefaults.LazyValue,- UIDefaults.ActiveValue,- Hashtable.get(java.lang.Object),- getDefaultLocale(),- addResourceBundle(java.lang.String)
 
 - 
getpublic Object get(Object key, Locale l) 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 key
- l- the desired- locale
- Returns:
- the value for key
- Since:
- 1.4
- See Also:
- UIDefaults.LazyValue,- UIDefaults.ActiveValue,- Hashtable.get(java.lang.Object),- addResourceBundle(java.lang.String)
 
 - 
putpublic Object put(Object key, Object value) 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 interface- Map<Object,Object>
- Overrides:
- putin class- Hashtable<Object,Object>
- Parameters:
- key- the unique- Objectwho's value will be used to retrieve the data value associated with it
- value- the new- Objectto store as data under that key
- Returns:
- the previous Objectvalue, ornull
- See Also:
- putDefaults(java.lang.Object[]),- Hashtable.put(K, V)
 
 - 
putDefaultspublic void putDefaults(Object[] keyValueList) 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:
- put(java.lang.Object, java.lang.Object),- Hashtable.put(K, V)
 
 - 
getFontpublic Font getFont(Object key) If the value ofkeyis aFontreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- Returns:
- if the value for keyis aFont, return theFontobject; otherwise returnnull
 
 - 
getFontpublic Font getFont(Object key, Locale l) If the value ofkeyfor the givenLocaleis aFontreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- l- the desired locale
- Returns:
- if the value for keyandLocaleis aFont, return theFontobject; otherwise returnnull
- Since:
- 1.4
 
 - 
getColorpublic Color getColor(Object key) If the value ofkeyis aColorreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- Returns:
- if the value for keyis aColor, return theColorobject; otherwise returnnull
 
 - 
getColorpublic Color getColor(Object key, Locale l) If the value ofkeyfor the givenLocaleis aColorreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- l- the desired locale
- Returns:
- if the value for keyandLocaleis aColor, return theColorobject; otherwise returnnull
- Since:
- 1.4
 
 - 
getIconpublic Icon getIcon(Object key) If the value ofkeyis anIconreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- Returns:
- if the value for keyis anIcon, return theIconobject; otherwise returnnull
 
 - 
getIconpublic Icon getIcon(Object key, Locale l) If the value ofkeyfor the givenLocaleis anIconreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- l- the desired locale
- Returns:
- if the value for keyandLocaleis anIcon, return theIconobject; otherwise returnnull
- Since:
- 1.4
 
 - 
getBorderpublic Border getBorder(Object key) If the value ofkeyis aBorderreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- Returns:
- if the value for keyis aBorder, return theBorderobject; otherwise returnnull
 
 - 
getBorderpublic Border getBorder(Object key, Locale l) If the value ofkeyfor the givenLocaleis aBorderreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- l- the desired locale
- Returns:
- if the value for keyandLocaleis aBorder, return theBorderobject; otherwise returnnull
- Since:
- 1.4
 
 - 
getStringpublic String getString(Object key) If the value ofkeyis aStringreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- Returns:
- if the value for keyis aString, return theStringobject; otherwise returnnull
 
 - 
getStringpublic String getString(Object key, Locale l) If the value ofkeyfor the givenLocaleis aStringreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- l- the desired- Locale
- Returns:
- if the value for keyfor the givenLocaleis aString, return theStringobject; otherwise returnnull
- Since:
- 1.4
 
 - 
getIntpublic int getInt(Object key) 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
 
 - 
getIntpublic int getInt(Object key, Locale l) If the value ofkeyfor the givenLocaleis anIntegerreturn 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
 
 - 
getBooleanpublic boolean getBoolean(Object key) If the value ofkeyis boolean, return the boolean value, otherwise return false.- Parameters:
- key- an- Objectspecifying the key for the desired boolean value
- Returns:
- if the value of keyis boolean, return the boolean value, otherwise return false.
- Since:
- 1.4
 
 - 
getBooleanpublic boolean getBoolean(Object key, Locale l) If the value ofkeyfor the givenLocaleis boolean, return the boolean value, otherwise return false.- Parameters:
- key- an- Objectspecifying 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
 
 - 
getInsetspublic Insets getInsets(Object key) If the value ofkeyis anInsetsreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- Returns:
- if the value for keyis anInsets, return theInsetsobject; otherwise returnnull
 
 - 
getInsetspublic Insets getInsets(Object key, Locale l) If the value ofkeyfor the givenLocaleis anInsetsreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- l- the desired locale
- Returns:
- if the value for keyandLocaleis anInsets, return theInsetsobject; otherwise returnnull
- Since:
- 1.4
 
 - 
getDimensionpublic Dimension getDimension(Object key) If the value ofkeyis aDimensionreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- Returns:
- if the value for keyis aDimension, return theDimensionobject; otherwise returnnull
 
 - 
getDimensionpublic Dimension getDimension(Object key, Locale l) If the value ofkeyfor the givenLocaleis aDimensionreturn it, otherwise returnnull.- Parameters:
- key- the desired key
- l- the desired locale
- Returns:
- if the value for keyandLocaleis aDimension, return theDimensionobject; otherwise returnnull
- Since:
- 1.4
 
 - 
getUIClasspublic Class<? extends ComponentUI> getUIClass(String uiClassID, ClassLoader uiClassLoader) 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 ID
- uiClassLoader- the object which will load the class
- Returns:
- the value of Class.forName(get(uidClassID))
- See Also:
- getUI(javax.swing.JComponent)
 
 - 
getUIClasspublic Class<? extends ComponentUI> getUIClass(String uiClassID) 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)
 
 - 
getUIErrorprotected 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)
 
 - 
getUIpublic ComponentUI getUI(JComponent target) 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- the- JComponentwhich needs a UI
- Returns:
- the ComponentUIobject
 
-  Look up the name of the 
 - 
addPropertyChangeListenerpublic void addPropertyChangeListener(PropertyChangeListener listener) Adds aPropertyChangeListenerto the listener list. The listener is registered for all properties.A PropertyChangeEventwill get fired whenever a default is changed.- Parameters:
- listener- the- PropertyChangeListenerto be added
- See Also:
- PropertyChangeSupport
 
 - 
removePropertyChangeListenerpublic void removePropertyChangeListener(PropertyChangeListener listener) Removes aPropertyChangeListenerfrom the listener list. This removes aPropertyChangeListenerthat was registered for all properties.- Parameters:
- listener- the- PropertyChangeListenerto be removed
- See Also:
- PropertyChangeSupport
 
 - 
getPropertyChangeListenerspublic PropertyChangeListener[] 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
 
 - 
firePropertyChangeprotected void firePropertyChange(String propertyName, Object oldValue, Object newValue) 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 changed
- oldValue- the old value of the property
- newValue- the new value of the property
- See Also:
- PropertyChangeSupport
 
 - 
addResourceBundlepublic 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 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:
- ResourceBundle,- removeResourceBundle(java.lang.String),- ResourceBundle.getBundle(String, Locale, ClassLoader)
 
 - 
removeResourceBundlepublic 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)
 
 - 
setDefaultLocalepublic void setDefaultLocale(Locale l) 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(),- get(Object),- get(Object,Locale)
 
 - 
getDefaultLocalepublic Locale 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:
- setDefaultLocale(java.util.Locale),- get(Object),- get(Object,Locale)
 
 
- 
 
-