diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java index 9ff1ff0a..0b29bcdb 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -86,6 +86,7 @@ public abstract class FlatLaf private static final String DESKTOPFONTHINTS = "awt.font.desktophints"; private static List customDefaultsSources; + private Map 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 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)}. + *

+ * 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)}. + *

+ * The keys and values are strings in same format as in FlatLaf properties files. + *

+ * Sample that setups "FlatLaf Light" theme with red accent color: + *

{@code
+	 * FlatLaf laf = new FlatLightLaf();
+	 * laf.setExtraDefaults( Collections.singletonMap( "@accentColor", "#f00" ) );
+	 * FlatLaf.setup( laf );
+	 * }
+ * + * @since 1.6 + */ + public void setExtraDefaults( Map extraDefaults ) { + this.extraDefaults = extraDefaults; + } + private static void reSetLookAndFeel() { EventQueue.invokeLater( () -> { LookAndFeel lookAndFeel = UIManager.getLookAndFeel();