Package ca.corbett.extras
Class LookAndFeelManager
java.lang.Object
ca.corbett.extras.LookAndFeelManager
This is a simple wrapper class to manage the various look and feels that
spring-extras supports.
- Since:
- 2025-04-22
- Author:
- scorbo2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddChangeListener(ChangeListener listener) If you wish to be informed when the current Look and Feel changes, because you have perhaps set some custom colors across your UI, you can subscribe to receive notification when it happens.static StringReturns the class name of the current Look and Feel, or the string "unknown" if there is no Look and Feel set.static StringReturns the self-reported name of the current Look and Feel, or the string "unknown" if there is no Look and Feel set, or if the current Look and Feel does not self-report a name.static ColorgetLafColor(String key, Color defaultColor) Returns the Color for the specified key, or returns the defaultColor if the specified key returns nothing.static voidCan be invoked (ideally at application startup before any GUI elements are shown) to install all the "extra" LaFs that swing-extras supports, namely from the FlatLaf package and also JTattoo.static booleanisDark()Returns true if the current Look and Feel is a "dark" theme, false if it's a "light" theme.static booleanisLight()Returns true if the current Look and Feel is a "light" theme, false if it's a "dark" theme.static voidremoveChangeListener(ChangeListener listener) static voidGiven a class name for a LookAndFeel class, switch the current LaF to that one.static voidInvoke to switch the current LaF to the specified one (you can either get the LookAndFeelInfo from a LookAndFeelProperty via user input or you can specify it yourself).
-
Constructor Details
-
LookAndFeelManager
public LookAndFeelManager()
-
-
Method Details
-
installExtraLafs
public static void installExtraLafs()Can be invoked (ideally at application startup before any GUI elements are shown) to install all the "extra" LaFs that swing-extras supports, namely from the FlatLaf package and also JTattoo. With the JTattoo themes we have to tweak them a bit to avoid some wonky default behaviour with menus (it wants to show a sideways logo in every menu for some reason - we can disable it).Implementation note: this code is in a public static method instead of in a static initializer block because your app might not care about LaF, in which case you can just ignore this method and avoid whatever memory penalty in would otherwise incur.
-
switchLaf
Invoke to switch the current LaF to the specified one (you can either get the LookAndFeelInfo from a LookAndFeelProperty via user input or you can specify it yourself). -
switchLaf
Given a class name for a LookAndFeel class, switch the current LaF to that one. We make no check here to ensure that the given class actually exists.- Parameters:
className- The name of the LaF class in question.
-
getLafColor
Returns the Color for the specified key, or returns the defaultColor if the specified key returns nothing. -
getCurrentLafName
Returns the self-reported name of the current Look and Feel, or the string "unknown" if there is no Look and Feel set, or if the current Look and Feel does not self-report a name. -
getCurrentLafClassName
Returns the class name of the current Look and Feel, or the string "unknown" if there is no Look and Feel set. -
isLight
public static boolean isLight()Returns true if the current Look and Feel is a "light" theme, false if it's a "dark" theme. The mechanism for determining this is a bit loose, and may not be accurate in all cases. -
isDark
public static boolean isDark()Returns true if the current Look and Feel is a "dark" theme, false if it's a "light" theme. The mechanism for determining this is a bit loose, and may not be accurate in all cases. -
addChangeListener
If you wish to be informed when the current Look and Feel changes, because you have perhaps set some custom colors across your UI, you can subscribe to receive notification when it happens.Note: you'll only receive a ChangeEvent if the Look and Feel was switched via this class. If your code talks to UIManager directly, then this class is cut out of the loop and the ChangeEvent will not fire.
- Parameters:
listener- A ChangeListener to receive a change event when LaF changes.
-
removeChangeListener
-