java.lang.Object
org.bzdev.swing.DarkmodeMonitor
Class to track background color changes due to a pluggable look and
feel that toggles between normal mode and dark mode.
If the red, green, and blue components of a color have values less
than 128 (with the maximum being 255), then dark mode is set to true
otherwise it is false.
If the mode changes, the PropertyChangeEvent
will have a source equal to DarkmodeMonitor
.class, a
property name equal to "darkmode", and Boolean values for the
old value and new value fields.
To get the mode initially, call getDarkmode()
.
The methods that DarkmodeMonitor
provides do not have to be
called from the event dispatch thread.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a property change listener.static boolean
Get the current dark-mode state.static void
init()
Initialization.static void
Remove a property change listener.static void
Set the look and feel to a modified system look and feel.
-
Constructor Details
-
DarkmodeMonitor
public DarkmodeMonitor()
-
-
Method Details
-
getDarkmode
public static boolean getDarkmode()Get the current dark-mode state. This may be called after the look and feel is installed.- Returns:
- true if dark mode is being used; false otherwise
-
init
public static void init()Initialization. This may be called after the look and feel is installed. Until it is called, events will not be sent to listeners.getDarkmode()
will call this method automatically. -
addPropertyChangeListener
Add a property change listener.- Parameters:
listener
- the listener
-
removePropertyChangeListener
Remove a property change listener.- Parameters:
listener
- the listener
-
setSystemPLAF
public static void setSystemPLAF()Set the look and feel to a modified system look and feel. Some system look and feels have a dark caret on a dark background making the caret (cursor) hard to see. For JTextField, JTextArea, and JEditorPane, the look and feel is modified so that the caret color always matches the foreground color (that is, the text color) when using the settings provided by the look and feel.
-