Class LookAndFeelManager

java.lang.Object
ca.corbett.extras.LookAndFeelManager

public class LookAndFeelManager extends Object
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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    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 String
    Returns the class name of the current Look and Feel, or the string "unknown" if there is no Look and Feel set.
    static String
    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.
    static Color
    getLafColor(String key, Color defaultColor)
    Returns the Color for the specified key, or returns the defaultColor if the specified key returns nothing.
    static void
    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.
    static boolean
    Returns true if the current Look and Feel is a "dark" theme, false if it's a "light" theme.
    static boolean
    Returns true if the current Look and Feel is a "light" theme, false if it's a "dark" theme.
    static void
     
    static void
    switchLaf(String className)
    Given a class name for a LookAndFeel class, switch the current LaF to that one.
    static void
    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).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static void switchLaf(UIManager.LookAndFeelInfo info)
      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

      public static void switchLaf(String className)
      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

      public static Color getLafColor(String key, Color defaultColor)
      Returns the Color for the specified key, or returns the defaultColor if the specified key returns nothing.
    • getCurrentLafName

      public static String 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

      public static String 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

      public static void addChangeListener(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.

      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

      public static void removeChangeListener(ChangeListener listener)