mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-07 22:40:53 +03:00
Accent color: added FlatLaf.setExtraDefaults() for easy setting accent color at runtime (issue #233)
This commit is contained in:
@@ -86,6 +86,7 @@ public abstract class FlatLaf
|
||||
private static final String DESKTOPFONTHINTS = "awt.font.desktophints";
|
||||
|
||||
private static List<Object> customDefaultsSources;
|
||||
private Map<String, String> extraDefaults;
|
||||
|
||||
private String desktopPropertyName;
|
||||
private String desktopPropertyName2;
|
||||
@@ -464,7 +465,12 @@ public abstract class FlatLaf
|
||||
}
|
||||
|
||||
protected Properties getAdditionalDefaults() {
|
||||
return null;
|
||||
if( extraDefaults == null )
|
||||
return null;
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.putAll( extraDefaults );
|
||||
return properties;
|
||||
}
|
||||
|
||||
private void initResourceBundle( UIDefaults defaults, String bundleName ) {
|
||||
@@ -779,6 +785,38 @@ public abstract class FlatLaf
|
||||
customDefaultsSources.remove( folder );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extra UI defaults; or {@code null}.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public Map<String, String> getExtraDefaults() {
|
||||
return extraDefaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extra UI defaults, which are only used when setting up the application look and feel.
|
||||
* E.g. using {@link UIManager#setLookAndFeel(LookAndFeel)} or {@link #setup(LookAndFeel)}.
|
||||
* <p>
|
||||
* The extra defaults are useful for smaller additional defaults that may change.
|
||||
* E.g. accent color. Otherwise FlatLaf properties files should be used.
|
||||
* See {@link #registerCustomDefaultsSource(String)}.
|
||||
* <p>
|
||||
* The keys and values are strings in same format as in FlatLaf properties files.
|
||||
* <p>
|
||||
* Sample that setups "FlatLaf Light" theme with red accent color:
|
||||
* <pre>{@code
|
||||
* FlatLaf laf = new FlatLightLaf();
|
||||
* laf.setExtraDefaults( Collections.singletonMap( "@accentColor", "#f00" ) );
|
||||
* FlatLaf.setup( laf );
|
||||
* }</pre>
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
public void setExtraDefaults( Map<String, String> extraDefaults ) {
|
||||
this.extraDefaults = extraDefaults;
|
||||
}
|
||||
|
||||
private static void reSetLookAndFeel() {
|
||||
EventQueue.invokeLater( () -> {
|
||||
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
|
||||
|
||||
Reference in New Issue
Block a user