JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.34k stars 266 forks source link

Q: Accent Color #507

Closed pejax closed 2 years ago

pejax commented 2 years ago

I created a Swing App using JFormDesigner and FlatLaf. All components (Buttons, selection, CheckBoxes etc) play nice with the accent color provided by any of the FlatLaf themes - except for buttons I add in a FormDesigner panel. I checked the FlatLaf demo project but I could not find the problem. What do I have to set to enable Accent Color on a JButton?

pejax commented 2 years ago

I want to style a custom component with the current accentColor which is somehow extracted by FlatLaf from the current lookAndFeel. I do not understand how FlatLaf determines the accentColor from a theme and where it is stored for runtime use. How do. I access the accessColor at runtime? I tried UIManager.getDefaults but I could not find it. Any help?

pejax commented 2 years ago

I had a JButton selection problem and was able to fix it. The accentColor questions I could answer myself.

DevCharly commented 2 years ago

Regarding your second question: Use

Color accentColor = UIManager.getColor( "Component.accentColor" );

to get the accent color (PR #375).

But note that this does not work for the 3rd party IntelliJ themes from the FlatLaf IntelliJ Themes Pack. Those themes don't have single "accent color" property. You have to use another value from the UI defaults. E.g. Component.focusColor.

Use the FlatLaf UI Defaults Inspector in the FlatLaf Demo (menu "Options >Show UI defaults inspector" to inspect UI defaults of various themes.

pejax commented 2 years ago

Thanks for your reply. That is what I figured out - it is more complicated than I thought. I would have to evaluate if I am dealing with a light or dark theme and pick a color from different properties of an existing component - sometimes background, sometimes border. I dropped the idea and set a marker in a different way. The JButton problem occurred because I set it to selected (via JFormDesigner) and setDefaultButton(true) at initialization time which makes it look funky.

DevCharly commented 2 years ago

Have modified the IntelliJ Themes slightly. Component.accentColor UI property now has useful theme specific colors in all themes.

The change is in the latest 2.2-SNAPSHOT

pejax commented 2 years ago

Danke für die Änderung. 2.2 kann ich erst ausprobieren, wenn es ein offizielles Release gibt. Bei mir geht der Gradle Build nicht - irgendein Problem mit dev.nokee.jni-library. Das Problem kommt wahrscheinlich von meinem Apple Silicon M1 Rechner.

DevCharly commented 2 years ago

Danke für den Hinweis. Habs korrigiert. Gradle build geht jetzt auch auf M1 Macs.

pejax commented 2 years ago

Der Gradle build auf M1 Mac geht jetzt auch bei mir. Die Anpassung der Component.accentColor funktioniert prima, danke. Ich benutze es, um Filtertreffer in einem JTextField anzuzeigen - sieht jetzt in allen Themes konsistent aus. Jetzt gleich eine neues Release :-)

medmedin2014 commented 2 years ago

Any idea how to apply current accent color to some components after changing theme at runtime, I succeeded to apply it to separators by recalling UIManager.put("Separator.foreground", UIManager.getColor( "Component.focusColor" )) but labels foreground are reset to default color even while using JLabel.setForeground(UIManager.getColor( "Component.focusColor" )).