Closed manticore-projects closed 2 years ago
Some JLables with style classses
H00
,H0
,H1
should be Blue, all other labels Black.
Then you should not change the style classses h00
, h0
, h1
.
Instead create a new style class for the color and also assign it to the labels.
[style].myColoredTitle = foreground: #00f
myLabel.putClientProperty( "FlatLaf.styleClass", "h1 myColoredTitle" );
Thank you so much! It makes a lot of sense, when I see this now. I did not catch that possibility from the Documentation or Samples.
Works like a charm, but leads to more questions:
1) as far as I can see it, the Properties file would be read only from the Classpath. Is there a way, to read it from a plain File also?
Explanation: We would like to deploy a distinct Java SwingUI JAR, but customize as per customer as per configuration file only.
Of course I understand, that I could deploy a customConfig.jar
and put it into the classpath -- but that's rather cumbersome.
2) working around this challenge, I have defined Command Line Options ACCENT_COLOR
and CAPTION_COLOR
and then I try to overwrite the FlatLaf properties. This works well for CAPTION_COLOR
, but it does not work for ACCENT_COLOR
and derived colors of the components. Am I doing something wrong?
@background = lighten(#E6E6E6FF,16%)
@foreground = lighten(#000,32%)
@accentColor = #FF420EFF
if ( Settings.hasKey("ACCENT_COLOR") ) {
FlatLaf.setGlobalExtraDefaults( Collections.singletonMap( "@accentColor", Settings.getString("ACCENT_COLOR") ) );
}
if ( Settings.hasKey("CAPTION_COLOR") ) {
FlatLaf.setGlobalExtraDefaults( Collections.singletonMap( "[style].caption", "foreground: " + Settings.getString("CAPTION_COLOR") ) );
}
FlatLightLaf.registerCustomDefaultsSource( "com/manticore/themes" );
FlatLightLaf.setup( );
Accent color stays Orange #FF420EFF even when Settings.getString("ACCENT_COLOR")
returns #fbb018.
Although Labels of [style].caption
show the correct light blue according to Settings.getString("CAPTION_COLOR")
= #007cb7
Please how can I access the @accentColor
from Java?
laf.getExtraDefaults().get("@accentColor");
returns null (even when the accentColor is set and effective in the properties file. Same for
UIManager.getLookAndFeelDefaults().getColor("@accentColor");
UIManager.getLookAndFeelDefaults().getColor("accentColor");
In the meantime I work around by getting UI properties set to the accentColor, e. g.
UIManager.getLookAndFeelDefaults().getColor("List.selectionBackground");
- as far as I can see it, the Properties file would be read only from the Classpath. Is there a way, to read it from a plain File also?
Use FlatLaf.registerCustomDefaultsSource( File folder )
, which registers a folder where FlatLaf searches for properties files with custom UI defaults. https://www.formdev.com/flatlaf/how-to-customize/#application_properties
...
if ( Settings.hasKey("ACCENT_COLOR") ) { FlatLaf.setGlobalExtraDefaults( Collections.singletonMap( "@accentColor", Settings.getString("ACCENT_COLOR") ) ); } if ( Settings.hasKey("CAPTION_COLOR") ) { FlatLaf.setGlobalExtraDefaults( Collections.singletonMap( "[style].caption", "foreground: " + Settings.getString("CAPTION_COLOR") ) ); } FlatLightLaf.registerCustomDefaultsSource( "com/manticore/themes" ); FlatLightLaf.setup( );
The problem with this code is that you invoke FlatLaf.setGlobalExtraDefaults()
twice and the second one replaces the first one. Invoke FlatLaf.setGlobalExtraDefaults()
only once and put all values into one map.
Thank you very much. This makes it clear and I appreciate.
Please how can I access the
@accentColor
from Java?
Keys starting with @
are variables with are only used while processing properties files, but are now available in UI defaults. See https://www.formdev.com/flatlaf/properties-files/#variables
There are two workarounds:
accentColor = @accentColor
to your FlatLaf.properties
. Then you can use UIManager.getColor( "accentColor" )
.FlatLaf.parseDefaultsValue( "accentColor", "@accentColor", null )
Greetings!
First of all, thank you for this amazing software. We do love it.
Although I have a question. We want to used JLabels and assign style classes
H00
,H0
,H1
as Captions and want to show them in a different color. This colour should be customisable (in order to reflect our customer's corporate design).In short: Some JLables with style classses
H00
,H0
,H1
should be Blue, all other labels Black.How can I achieve that with a Property File? I would like to avoid setting the Blue Colour in the Java Code itself if possible.
My property file so far looks like this: