fixed white lines at bottom and right side of window (in dark themes on HiDPI screens with scaling enabled)

This commit is contained in:
Karl Tauber
2021-06-11 16:16:41 +02:00
parent b26dbe81f4
commit 7b248427f0
2 changed files with 44 additions and 0 deletions

View File

@@ -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

View File

@@ -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
*/