How to implement editors for specific themes (e.g. Darcula)?


I want to develop an editor that reacts differently based on the selected UI theme.

How can I determine which UI theme is currently selected?

I plan on defining a specific stylesheet where the background and font colors are determined based on the UI theme.


Best regards!


I'm currently using something like this to detect the Darcula mode:

public static boolean isDarculaTheme() { 
 LafManager lafManager = LafManager.getInstance(); 
 LafManager.LafReference lookAndFeelReference = lafManager.getLookAndFeelReference(); 
 string themeName = lookAndFeelReference.getClassName(); 
 string darculaThemeName = DarculaLaf.class.getName(); 
 boolean isDarculaTheme = themeName :eq: darculaThemeName; 
 log info "Is dark mode: " + isDarculaTheme, <no throwable>; 
 return isDarculaTheme; 

You can also return an instance of JBColor from any code (query) that should return a java.awt.Color. JBColor constructor takes two colors, light and dark, and will choose between them depending on the active theme.

In addition, style attributes taking a color allow specifying two colors directly as a light/dark pair.


Thank you, I will definitely try that!


Please sign in to leave a comment.