From 7b248427f00fdc7a77652e60ace058fe006a4288 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 11 Jun 2021 16:16:41 +0200 Subject: [PATCH] fixed white lines at bottom and right side of window (in dark themes on HiDPI screens with scaling enabled) --- CHANGELOG.md | 8 +++++ .../formdev/flatlaf/ui/FlatRootPaneUI.java | 36 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cea8f65..56a034e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ FlatLaf Change Log ================== +## 1.3-SNAPSHOT + +#### Fixed bugs + +- Fixed white lines at bottom and right side of window (in dark themes on HiDPI + screens with scaling enabled). + + ## 1.2 #### New features and improvements diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java index 286467c6..185e32c0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRootPaneUI.java @@ -27,6 +27,8 @@ import java.awt.Insets; import java.awt.LayoutManager; import java.awt.LayoutManager2; import java.awt.Window; +import java.awt.event.HierarchyEvent; +import java.awt.event.HierarchyListener; import java.beans.PropertyChangeEvent; import java.util.function.Function; import javax.swing.JComponent; @@ -79,6 +81,7 @@ public class FlatRootPaneUI private Object nativeWindowBorderData; private LayoutManager oldLayout; + private HierarchyListener hierarchyListener; public static ComponentUI createUI( JComponent c ) { return new FlatRootPaneUI(); @@ -136,6 +139,39 @@ public class FlatRootPaneUI c.putClientProperty( "jetbrains.awt.windowDarkAppearance", FlatLaf.isLafDark() ); } + @Override + protected void installListeners( JRootPane root ) { + super.installListeners( root ); + + if( SystemInfo.isJava_9_orLater ) { + // On HiDPI screens, where scaling is used, there may be white lines at the + // bottom and at the right side of the window when it is initially shown. + // This is very disturbing in dark themes, but hard to notice in light themes. + // Seems to be a rounding issue when Swing adds dirty region of window + // using RepaintManager.nativeAddDirtyRegion(). + hierarchyListener = e -> { + if( (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && + rootPane.getParent() instanceof Window ) + { + // add whole root pane to dirty regions when window is initially shown + rootPane.getParent().repaint( rootPane.getX(), rootPane.getY(), + rootPane.getWidth(), rootPane.getHeight() ); + } + }; + root.addHierarchyListener( hierarchyListener ); + } + } + + @Override + protected void uninstallListeners( JRootPane root ) { + super.uninstallListeners( root ); + + if( SystemInfo.isJava_9_orLater ) { + root.removeHierarchyListener( hierarchyListener ); + hierarchyListener = null; + } + } + /** * @since 1.1.2 */