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 1a1040d5..8dd0149c 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/FlatSystemProperties.java @@ -55,13 +55,13 @@ public interface FlatSystemProperties String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont"; /** - * Specifies whether FlatLaf native window decorations should be used + * Specifies whether native window decorations should be used * when creating {@code JFrame} or {@code JDialog}. *

- * Setting this to {@code true} forces using FlatLaf native window decorations + * Setting this to {@code true} forces using native window decorations * even if they are not enabled by the application. *

- * Setting this to {@code false} disables using FlatLaf native window decorations. + * Setting this to {@code false} disables using native window decorations. *

* This system property has higher priority than client property * {@link FlatClientProperties#USE_WINDOW_DECORATIONS} and @@ -81,15 +81,13 @@ public interface FlatSystemProperties * JetBrains Runtime * (based on OpenJDK). *

- * Setting this to {@code true} forces using JetBrains Runtime custom window decorations - * even if they are not enabled by the application. - *

* Setting this to {@code false} disables using JetBrains Runtime custom window decorations. + * Then FlatLaf native window decorations are used. *

* (requires Window 10) *

* Allowed Values {@code false} and {@code true}
- * Default none + * Default true */ String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations"; diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java index 49a0332f..688bfbfe 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java @@ -41,9 +41,22 @@ import com.formdev.flatlaf.util.SystemInfo; */ public class FlatNativeWindowBorder { + // can use window decorations if: + // - on Windows 10 + // - not when running in JetBrains Projector, Webswing or WinPE + // - not disabled via system property + private static final boolean canUseWindowDecorations = + SystemInfo.isWindows_10_orLater && + !SystemInfo.isProjector && + !SystemInfo.isWebswing && + !SystemInfo.isWinPE && + FlatSystemProperties.getBoolean( FlatSystemProperties.USE_WINDOW_DECORATIONS, true ); + // check this field before using class JBRCustomDecorations to avoid unnecessary loading of that class - private static final boolean canUseJBRCustomDecorations - = SystemInfo.isJetBrainsJVM_11_orLater && SystemInfo.isWindows_10_orLater; + private static final boolean canUseJBRCustomDecorations = + canUseWindowDecorations && + SystemInfo.isJetBrainsJVM_11_orLater && + FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true ); private static Boolean supported; private static Provider nativeProvider; @@ -72,7 +85,7 @@ public class FlatNativeWindowBorder // It could be also be a window that is currently hidden, but may be shown later. Window window = SwingUtilities.windowForComponent( rootPane ); if( window != null && window.isDisplayable() ) - install( window, FlatSystemProperties.USE_WINDOW_DECORATIONS ); + install( window ); // Install FlatLaf native window border, which must be done late, // when the native window is already created, because it needs access to the window. @@ -81,7 +94,7 @@ public class FlatNativeWindowBorder PropertyChangeListener ancestorListener = e -> { Object newValue = e.getNewValue(); if( newValue instanceof Window ) - install( (Window) newValue, FlatSystemProperties.USE_WINDOW_DECORATIONS ); + install( (Window) newValue ); else if( newValue == null && e.getOldValue() instanceof Window ) uninstall( (Window) e.getOldValue() ); }; @@ -89,7 +102,7 @@ public class FlatNativeWindowBorder return ancestorListener; } - static void install( Window window, String systemPropertyKey ) { + static void install( Window window ) { if( hasCustomDecoration( window ) ) return; @@ -102,7 +115,7 @@ public class FlatNativeWindowBorder JRootPane rootPane = frame.getRootPane(); // check whether disabled via system property, client property or UI default - if( !useWindowDecorations( rootPane, systemPropertyKey ) ) + if( !useWindowDecorations( rootPane ) ) return; // do not enable native window border if frame is undecorated @@ -120,7 +133,7 @@ public class FlatNativeWindowBorder JRootPane rootPane = dialog.getRootPane(); // check whether disabled via system property, client property or UI default - if( !useWindowDecorations( rootPane, systemPropertyKey ) ) + if( !useWindowDecorations( rootPane ) ) return; // do not enable native window border if dialog is undecorated @@ -149,7 +162,7 @@ public class FlatNativeWindowBorder rootPane.removePropertyChangeListener( "ancestor", (PropertyChangeListener) data ); // do not uninstall when switching to another FlatLaf theme and if still enabled - if( UIManager.getLookAndFeel() instanceof FlatLaf && useWindowDecorations( rootPane, FlatSystemProperties.USE_WINDOW_DECORATIONS ) ) + if( UIManager.getLookAndFeel() instanceof FlatLaf && useWindowDecorations( rootPane ) ) return; // uninstall native window border @@ -179,9 +192,9 @@ public class FlatNativeWindowBorder } } - private static boolean useWindowDecorations( JRootPane rootPane, String systemPropertyKey ) { + private static boolean useWindowDecorations( JRootPane rootPane ) { // check whether forced to enabled/disabled via system property - Boolean enabled = FlatSystemProperties.getBooleanStrict( systemPropertyKey, null ); + Boolean enabled = FlatSystemProperties.getBooleanStrict( FlatSystemProperties.USE_WINDOW_DECORATIONS, null ); if( enabled != null ) return enabled; @@ -243,16 +256,7 @@ public class FlatNativeWindowBorder return; supported = false; - // requires Windows 10 - if( !SystemInfo.isWindows_10_orLater ) - return; - - // do not use when running in JetBrains Projector, Webswing or WinPE - if( SystemInfo.isProjector || SystemInfo.isWebswing || SystemInfo.isWinPE ) - return; - - // check whether disabled via system property - if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_WINDOW_DECORATIONS, true ) ) + if( !canUseWindowDecorations ) return; try { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index 06a30087..7acac163 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -36,7 +36,6 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.plaf.BorderUIResource; import com.formdev.flatlaf.FlatLaf; -import com.formdev.flatlaf.FlatSystemProperties; import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.SystemInfo; @@ -73,7 +72,7 @@ public class JBRCustomDecorations // check whether root pane already has a parent, which is the case when switching LaF Window window = SwingUtilities.windowForComponent( rootPane ); if( window != null ) { - FlatNativeWindowBorder.install( window, FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS ); + FlatNativeWindowBorder.install( window ); return null; } @@ -89,7 +88,7 @@ public class JBRCustomDecorations Container parent = e.getChangedParent(); if( parent instanceof Window ) - FlatNativeWindowBorder.install( (Window) parent, FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS ); + FlatNativeWindowBorder.install( (Window) parent ); // remove listener since it is actually not possible to uninstall JBR decorations // use invokeLater to remove listener to avoid that listener @@ -165,10 +164,6 @@ public class JBRCustomDecorations if( !SystemInfo.isJetBrainsJVM_11_orLater || !SystemInfo.isWindows_10_orLater ) return; - // check whether disabled via system property - if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true ) ) - return; - try { Class awtAcessorClass = Class.forName( "sun.awt.AWTAccessor" ); Class compAccessorClass = Class.forName( "sun.awt.AWTAccessor$ComponentAccessor" );