diff --git a/CHANGELOG.md b/CHANGELOG.md index b44ee9e23..3d739a492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ FlatLaf Change Log - Native window decorations (Windows 10/11 only): Added client property to mark components in embedded menu bar as "caption" (allow moving window). (issue #569) +- Added system property `flatlaf.updateUIOnSystemFontChange` to allow disabling + automatic UI update when system font changes. (issue #580) #### Fixed bugs 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 570a0a1bb..2ad80500c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatLaf.java @@ -276,6 +276,9 @@ public void initialize() { } if( desktopPropertyName != null ) { desktopPropertyListener = e -> { + if( !FlatSystemProperties.getBoolean( FlatSystemProperties.UPDATE_UI_ON_SYSTEM_FONT_CHANGE, true ) ) + return; + String propertyName = e.getPropertyName(); if( desktopPropertyName.equals( propertyName ) || propertyName.equals( desktopPropertyName2 ) ) reSetLookAndFeel(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java index 024a36880..2aa906d8a 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf; +import javax.swing.SwingUtilities; import com.formdev.flatlaf.util.UIScale; /** @@ -139,6 +140,20 @@ public interface FlatSystemProperties */ String USE_TEXT_Y_CORRECTION = "flatlaf.useTextYCorrection"; + /** + * Specifies whether FlatLaf updates the UI when the system font changes. + * If {@code true}, {@link SwingUtilities#updateComponentTreeUI(java.awt.Component)} + * gets invoked for all windows if the system font has changed. + * This is the similar to when switching to another look and feel (theme). + * Applications that do not work correctly when switching look and feel, + * should disable this option to avoid corrupted UI. + *

+ * Allowed Values {@code false} and {@code true}
+ * Default {@code true} + * @since 2.5 + */ + String UPDATE_UI_ON_SYSTEM_FONT_CHANGE = "flatlaf.updateUIOnSystemFontChange"; + /** * Specifies a directory in which the native FlatLaf library have been extracted. * The path can be absolute or relative to current application working directory.