From d0817653f87974bb68d413a2d5790c92b495ce34 Mon Sep 17 00:00:00 2001 From: weisj Date: Fri, 6 Mar 2020 12:57:59 +0100 Subject: [PATCH] Fixed incorrect window size/location when using setSize/setPreferredSize. --- .../darklaf/ui/rootpane/DarkRootPaneUI.java | 16 +++++++++++++++- .../ui/rootpane/DarkSubstanceRootLayout.java | 3 +-- .../platform/macos/ui/MacOSTitlePane.java | 3 +-- .../platform/windows/JNIDecorationsWindows.java | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java index 77e68beb..a83b9a87 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java @@ -196,11 +196,25 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener updateClientDecoration(); } if (e.getChangeFlags() == HierarchyEvent.SHOWING_CHANGED) { + if (!window.isShowing()) return; /* * Force the window peer to relayout and repaint. * e.g. on windows this is necessary to properly remove the title bar. */ - window.pack(); + Rectangle bounds = window.getBounds(); + Dimension size = bounds.getSize(); + Point p = bounds.getLocation(); + if (window.isPreferredSizeSet()) { + size = window.getPreferredSize(); + } else { + p.x += size.width / 2; + p.y += size.height / 2; + } + //Resizing triggers #reshapeNativePeer + window.setSize(size.width, size.height + 1); + window.setSize(size.width, size.height); + window.setLocation(p.x - size.width / 2, + p.y - size.height / 2); } } diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkSubstanceRootLayout.java b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkSubstanceRootLayout.java index 1f8551d0..e7e677be 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkSubstanceRootLayout.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkSubstanceRootLayout.java @@ -144,8 +144,7 @@ class DarkSubstanceRootLayout implements LayoutManager2 { } protected CustomTitlePane getTitlePane(final JRootPane root) { - if ((root.getWindowDecorationStyle() != JRootPane.NONE) - && (root.getUI() instanceof DarkRootPaneUI)) { + if (root.getUI() instanceof DarkRootPaneUI) { return ((DarkRootPaneUI) root.getUI()).getTitlePane(); } return null; diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java index 78e338b3..4f134470 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java @@ -200,8 +200,7 @@ public class MacOSTitlePane extends CustomTitlePane { boolean isFullscreen = JNIDecorationsMacOS.isFullscreen(decorationInformation.windowHandle); return (decorationInformation != null && decorationInformation.windowHandle == 0) || isFullscreen - || getWindowDecorationStyle() == JRootPane.NONE - || getTitle().length() == 0; + || getWindowDecorationStyle() == JRootPane.NONE; } private boolean useCustomTitle() { diff --git a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java index e7193c04..e76cd6e5 100644 --- a/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java +++ b/windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java @@ -64,6 +64,7 @@ public class JNIDecorationsWindows { } private static void loadLibrary() { + attemptedLoad = true; if (!SystemInfo.isWindows || loaded) { return; }