Class LookAndFeelAddons
java.lang.Object
org.jdesktop.swingx.plaf.LookAndFeelAddons
- Direct Known Subclasses:
BasicLookAndFeelAddons
Provides additional pluggable UI for new components added by the library. By default, the library
uses the pluggable UI returned by
getBestMatchAddonClassName().
The default addon can be configured using the swing.addon system property as follow:
- on the command line,
java -Dswing.addon=ADDONCLASSNAME ... - at runtime and before using the library components
System.getProperties().put("swing.addon", ADDONCLASSNAME);
The default cross platform addon can be configured
using the swing.crossplatformlafaddon system property as follow:
- on the command line,
java -Dswing.crossplatformlafaddon=ADDONCLASSNAME ... - at runtime and before using the library components
System.getProperties().put("swing.crossplatformlafaddon", ADDONCLASSNAME);
Note: changing this property after the UI has been initialized may result in unexpected behavior.
The addon can also be installed directly by calling the setAddon(String)method. For
example, to install the Windows addons, add the following statement
LookAndFeelAddons.setAddon("org.jdesktop.swingx.plaf.windows.WindowsLookAndFeelAddons");.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ObjectKey used to ensure the current UIManager has been populated by the LookAndFeelAddons.private static PropertyChangeListenerprivate static List<ComponentAddon> private static LookAndFeelAddonsprivate static boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidbarkOnUIError(String message) static voidcontribute(ComponentAddon component) Each new component added by the library will contribute its default UI classes, colors and fonts to the LookAndFeelAddons.static LookAndFeelAddonsgetAddon()static StringBased on the current look and feel (as returned byUIManager.getLookAndFeel()), this method returns the name of the closestLookAndFeelAddonsto use.private static ClassLoaderstatic Stringstatic StringGets the addon best suited for the operating system where the virtual machine is running.static ComponentUIgetUI(JComponent component, Class<?> expectedUIClass) Workaround for IDE mixing up with classloaders and Applets environments.voidInitializes the look and feel addon.static voidinstallBackgroundPainter(JComponent c, String painter) Convenience method for setting a component's background painter property with a value from the defaults.protected booleanDetermines if the addon is a match for the system Look and Feel.static booleanvoidloadDefaults(Object[] keysAndValues) Adds the given defaults in UIManager.protected booleanmatches()Determines if the addon is a match for thecurrent Look and Feel.private static voidWith applets, if you reload the current applet, the UIManager will be reinitialized (entries previously added by LookAndFeelAddons will be removed) but the addon will not reinitialize because addon initialize itself through the static block in components and the classes do not get reloaded.static voidstatic voidstatic voidsetAddon(LookAndFeelAddons addon) static voidsetTrackingLookAndFeelChanges(boolean tracking) If true, everytime the Swing look and feel is changed, the addon which best matches the current look and feel will be automatically selected.static voiduncontribute(ComponentAddon component) Removes the contribution of the given addonvoidstatic voidConvenience method for uninstalling a background painter.voidunloadDefaults(Object[] keysAndValues)
-
Field Details
-
contributedComponents
-
APPCONTEXT_INITIALIZED
Key used to ensure the current UIManager has been populated by the LookAndFeelAddons. -
trackingChanges
private static boolean trackingChanges -
changeListener
-
currentAddon
-
-
Constructor Details
-
LookAndFeelAddons
public LookAndFeelAddons()
-
-
Method Details
-
matches
protected boolean matches()Determines if the addon is a match for thecurrent Look and Feel.- Returns:
trueif this addon matches (is compatible);falseotherwise
-
isSystemAddon
protected boolean isSystemAddon()Determines if the addon is a match for the system Look and Feel.- Returns:
trueif this addon matches (is compatible with) the system Look and Feel;falseotherwise
-
initialize
public void initialize()Initializes the look and feel addon. This method is- See Also:
-
uninitialize
public void uninitialize() -
loadDefaults
Adds the given defaults in UIManager. Note: the values are added only if they do not exist in the existing look and feel defaults. This makes it possible for look and feel implementors to override SwingX defaults. Note: the array is traversed in reverse order. If a key is found twice in the array, the key/value with the highest position in the array gets precedence over the other key in the array- Parameters:
keysAndValues-
-
unloadDefaults
-
setAddon
public static void setAddon(String addonClassName) throws InstantiationException, IllegalAccessException, ClassNotFoundException -
setAddon
public static void setAddon(Class<?> addonClass) throws InstantiationException, IllegalAccessException -
setAddon
-
getAddon
-
getClassLoader
-
getBestMatchAddonClassName
Based on the current look and feel (as returned byUIManager.getLookAndFeel()), this method returns the name of the closestLookAndFeelAddonsto use.- Returns:
- the addon matching the currently installed look and feel
-
getCrossPlatformAddonClassName
-
getSystemAddonClassName
Gets the addon best suited for the operating system where the virtual machine is running.- Returns:
- the addon matching the native operating system platform.
-
contribute
Each new component added by the library will contribute its default UI classes, colors and fonts to the LookAndFeelAddons. SeeComponentAddon.- Parameters:
component-
-
uncontribute
Removes the contribution of the given addon- Parameters:
component-
-
getUI
Workaround for IDE mixing up with classloaders and Applets environments. Consider this method as API private. It must not be called directly.- Parameters:
component-expectedUIClass-- Returns:
- an instance of expectedUIClass
-
barkOnUIError
-
maybeInitialize
private static void maybeInitialize()With applets, if you reload the current applet, the UIManager will be reinitialized (entries previously added by LookAndFeelAddons will be removed) but the addon will not reinitialize because addon initialize itself through the static block in components and the classes do not get reloaded. This means component.updateUI will fail because it will not find its UI. This method ensures LookAndFeelAddons get re-initialized if needed. It must be called in every component updateUI methods. -
setTrackingLookAndFeelChanges
public static void setTrackingLookAndFeelChanges(boolean tracking) If true, everytime the Swing look and feel is changed, the addon which best matches the current look and feel will be automatically selected.- Parameters:
tracking- true to automatically update the addon, false to not automatically track the addon. Defaults to false.- See Also:
-
isTrackingLookAndFeelChanges
public static boolean isTrackingLookAndFeelChanges()- Returns:
- true if the addon will be automatically change to match the current look and feel
- See Also:
-
installBackgroundPainter
Convenience method for setting a component's background painter property with a value from the defaults. The painter is only set if the painter isnullor an instance ofUIResource.- Parameters:
c- component to set the painter onpainter- key specifying the painter- Throws:
NullPointerException- if the component or painter isnullIllegalArgumentException- if the component does not contain the "backgroundPainter" property or the property cannot be set
-
uninstallBackgroundPainter
Convenience method for uninstalling a background painter. If the painter of the component is aUIResource, it is set tonull.- Parameters:
c- component to uninstall the painter on- Throws:
NullPointerException- ifcisnullIllegalArgumentException- if the component does not contain the "backgroundPainter" property or the property cannot be set
-