diff --git a/core/src/main/java/com/github/weisj/darklaf/LafManager.java b/core/src/main/java/com/github/weisj/darklaf/LafManager.java index 49d9d33c..9efb655a 100644 --- a/core/src/main/java/com/github/weisj/darklaf/LafManager.java +++ b/core/src/main/java/com/github/weisj/darklaf/LafManager.java @@ -193,28 +193,8 @@ public final class LafManager { } SwingUtilities.updateComponentTreeUI(window); // Use custom decorations when supported by the LAF - if (window instanceof JFrame) { - JFrame frame = (JFrame) window; - frame.dispose(); - if (UIManager.getLookAndFeel().getSupportsWindowDecorations()) { - frame.setUndecorated(true); - frame.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); - } else { - frame.setUndecorated(false); - } - frame.setVisible(true); - } else if (window instanceof JDialog) { - JDialog dialog = (JDialog) window; - boolean isVisible = dialog.isVisible(); - dialog.dispose(); - if (UIManager.getLookAndFeel().getSupportsWindowDecorations()) { - dialog.setUndecorated(true); - dialog.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); - } else { - dialog.setUndecorated(false); - } - dialog.setVisible(isVisible); - } + window.dispose(); + window.setVisible(true); } /** 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 4fdff514..38e62ec8 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 @@ -34,6 +34,8 @@ import javax.swing.plaf.basic.BasicRootPaneUI; import java.awt.*; import java.awt.event.HierarchyEvent; import java.awt.event.HierarchyListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; @@ -48,6 +50,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener private LayoutManager layoutManager; private LayoutManager oldLayout; private JRootPane rootPane; + private DisposeListener disposeListener = new DisposeListener(); private boolean decorationStyleLock = false; private int windowDecorationsStyle = -1; @@ -110,6 +113,7 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener } if (window != null) { window.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + window.removeWindowListener(disposeListener); } window = null; } @@ -159,7 +163,9 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener } private void updateWindow(final Component parent) { + if (window != null) window.removeWindowListener(disposeListener); window = DarkUIUtil.getWindow(parent); + if (window != null) window.addWindowListener(disposeListener); } private void installLayout(final JRootPane root) { @@ -225,4 +231,11 @@ public class DarkRootPaneUI extends BasicRootPaneUI implements HierarchyListener installClientDecorations(rootPane); } } + + protected class DisposeListener extends WindowAdapter { + @Override + public void windowClosing(final WindowEvent e) { + uninstallClientDecorations(rootPane); + } + } } diff --git a/macos/src/main/objectiveCpp/JNIDecorations.mm b/macos/src/main/objectiveCpp/JNIDecorations.mm index d0ec6f95..9bb01eef 100644 --- a/macos/src/main/objectiveCpp/JNIDecorations.mm +++ b/macos/src/main/objectiveCpp/JNIDecorations.mm @@ -67,9 +67,10 @@ Java_com_github_weisj_darklaf_platform_macos_JNIDecorationsMacOS_releaseWindow(J JNIEXPORT jdouble JNICALL Java_com_github_weisj_darklaf_platform_macos_JNIDecorationsMacOS_getTitleBarHeight(JNIEnv *env, jclass obj, jlong hwnd) { NSWindow *nsWindow = OBJC(hwnd); - CGFloat windowFrameHeight = nsWindow.contentView.frame.size.height; - CGFloat contentLayoutRectHeight = nsWindow.contentLayoutRect.size.height; - return (jdouble)(windowFrameHeight - contentLayoutRectHeight); + NSRect frame = NSMakeRect(0.0, 0.0, 100.0, 100.0); + NSUInteger windowStyle = nsWindow.styleMask & ~NSWindowStyleMaskFullSizeContentView; + NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:windowStyle]; + return (jdouble)(frame.size.height - rect.size.height); } JNIEXPORT jboolean JNICALL