Browse Source

Fixed incorrect window size/location when using setSize/setPreferredSize.

pull/75/head
weisj 5 years ago
parent
commit
d0817653f8
  1. 16
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  2. 3
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkSubstanceRootLayout.java
  3. 3
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java
  4. 1
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java

16
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java

@ -196,11 +196,25 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener
updateClientDecoration(); updateClientDecoration();
} }
if (e.getChangeFlags() == HierarchyEvent.SHOWING_CHANGED) { if (e.getChangeFlags() == HierarchyEvent.SHOWING_CHANGED) {
if (!window.isShowing()) return;
/* /*
* Force the window peer to relayout and repaint. * Force the window peer to relayout and repaint.
* e.g. on windows this is necessary to properly remove the title bar. * 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);
} }
} }

3
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) { protected CustomTitlePane getTitlePane(final JRootPane root) {
if ((root.getWindowDecorationStyle() != JRootPane.NONE) if (root.getUI() instanceof DarkRootPaneUI) {
&& (root.getUI() instanceof DarkRootPaneUI)) {
return ((DarkRootPaneUI) root.getUI()).getTitlePane(); return ((DarkRootPaneUI) root.getUI()).getTitlePane();
} }
return null; return null;

3
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); boolean isFullscreen = JNIDecorationsMacOS.isFullscreen(decorationInformation.windowHandle);
return (decorationInformation != null && decorationInformation.windowHandle == 0) return (decorationInformation != null && decorationInformation.windowHandle == 0)
|| isFullscreen || isFullscreen
|| getWindowDecorationStyle() == JRootPane.NONE || getWindowDecorationStyle() == JRootPane.NONE;
|| getTitle().length() == 0;
} }
private boolean useCustomTitle() { private boolean useCustomTitle() {

1
windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java

@ -64,6 +64,7 @@ public class JNIDecorationsWindows {
} }
private static void loadLibrary() { private static void loadLibrary() {
attemptedLoad = true;
if (!SystemInfo.isWindows || loaded) { if (!SystemInfo.isWindows || loaded) {
return; return;
} }

Loading…
Cancel
Save