From c32c00a5eb90b681e594f59d39ccb227d19963d6 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Sun, 26 Jan 2025 17:48:19 +0100 Subject: [PATCH] Linux with FlatLaf window decorations: - moved window resizer components from layered pane to rootpane so that border is included in area where user can resize window - scale border thickness --- .../formdev/flatlaf/ui/FlatRootPaneUI.java | 7 ++-- .../formdev/flatlaf/ui/FlatWindowResizer.java | 35 ++++++++----------- 2 files changed, 19 insertions(+), 23 deletions(-) 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 3cb17f34..d5b77bfa 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 @@ -684,7 +684,7 @@ public class FlatRootPaneUI * Window border used for non-native window decorations. */ public static class FlatWindowBorder - extends BorderUIResource.EmptyBorderUIResource + extends FlatEmptyBorder { protected final Color activeBorderColor = UIManager.getColor( "RootPane.activeBorderColor" ); protected final Color inactiveBorderColor = UIManager.getColor( "RootPane.inactiveBorderColor" ); @@ -717,7 +717,10 @@ public class FlatRootPaneUI } private void paintImpl( Graphics2D g, int x, int y, int width, int height, double scaleFactor ) { - g.drawRect( x, y, width - 1, height - 1 ); + Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g ); + float lineWidth = (float) (UIScale.scale( 1f ) * scaleFactor); + g.fill( FlatUIUtils.createRectangle( x, y, width, height, lineWidth ) ); + FlatUIUtils.resetRenderingHints( g, oldRenderingHints ); } protected boolean isWindowMaximized( Component c ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java index 99f0817e..06f75a2e 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatWindowResizer.java @@ -41,7 +41,6 @@ import java.util.function.Supplier; import javax.swing.DesktopManager; import javax.swing.JComponent; import javax.swing.JInternalFrame; -import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.SwingUtilities; @@ -60,8 +59,6 @@ import com.formdev.flatlaf.util.UIScale; public abstract class FlatWindowResizer implements PropertyChangeListener, ComponentListener { - protected final static Integer WINDOW_RESIZER_LAYER = JLayeredPane.DRAG_LAYER + 1; - protected final JComponent resizeComp; protected final int borderDragThickness = FlatUIUtils.getUIInt( "RootPane.borderDragThickness", 5 ); @@ -82,12 +79,12 @@ public abstract class FlatWindowResizer leftDragComp = createDragBorderComponent( NW_RESIZE_CURSOR, W_RESIZE_CURSOR, SW_RESIZE_CURSOR ); rightDragComp = createDragBorderComponent( NE_RESIZE_CURSOR, E_RESIZE_CURSOR, SE_RESIZE_CURSOR ); - Container cont = (resizeComp instanceof JRootPane) ? ((JRootPane)resizeComp).getLayeredPane() : resizeComp; - Object cons = (cont instanceof JLayeredPane) ? WINDOW_RESIZER_LAYER : null; - cont.add( topDragComp, cons, 0 ); - cont.add( bottomDragComp, cons, 1 ); - cont.add( leftDragComp, cons, 2 ); - cont.add( rightDragComp, cons, 3 ); + // for rootpanes, add after glasspane + int insertIndex = (resizeComp instanceof JRootPane) ? 1 : 0; + resizeComp.add( topDragComp, insertIndex++ ); + resizeComp.add( bottomDragComp, insertIndex++ ); + resizeComp.add( leftDragComp, insertIndex++ ); + resizeComp.add( rightDragComp, insertIndex++ ); resizeComp.addComponentListener( this ); resizeComp.addPropertyChangeListener( "ancestor", this ); @@ -106,11 +103,10 @@ public abstract class FlatWindowResizer resizeComp.removeComponentListener( this ); resizeComp.removePropertyChangeListener( "ancestor", this ); - Container cont = topDragComp.getParent(); - cont.remove( topDragComp ); - cont.remove( bottomDragComp ); - cont.remove( leftDragComp ); - cont.remove( rightDragComp ); + resizeComp.remove( topDragComp ); + resizeComp.remove( bottomDragComp ); + resizeComp.remove( leftDragComp ); + resizeComp.remove( rightDragComp ); } public void doLayout() { @@ -119,9 +115,8 @@ public abstract class FlatWindowResizer int x = 0; int y = 0; - Container cont = topDragComp.getParent(); - int width = cont.getWidth(); - int height = cont.getHeight(); + int width = resizeComp.getWidth(); + int height = resizeComp.getHeight(); if( width <= 0 || height <= 0 ) return; @@ -252,8 +247,7 @@ public abstract class FlatWindowResizer centerComp = new JPanel(); centerComp.setOpaque( false ); centerComp.setVisible( false ); - Container cont = rootPane.getLayeredPane(); - cont.add( centerComp, WINDOW_RESIZER_LAYER, 4 ); + rootPane.add( centerComp, 5 ); // On Linux, limit window resizing to screen bounds because otherwise // there would be a strange effect when the mouse is moved over a sidebar @@ -263,8 +257,7 @@ public abstract class FlatWindowResizer @Override public void uninstall() { - Container cont = topDragComp.getParent(); - cont.remove( centerComp ); + resizeComp.remove( centerComp ); super.uninstall(); }