diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSDecorationsProvider.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSDecorationsProvider.java index 2eb5c07c..f85430ea 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSDecorationsProvider.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/MacOSDecorationsProvider.java @@ -67,7 +67,11 @@ public class MacOSDecorationsProvider implements DecorationsProvider { public TitlePaneLayoutInfo titlePaneLayoutInfo(final CustomTitlePane customTitlePane) { if (!(customTitlePane instanceof MacOSTitlePane)) throw new IllegalStateException(); long hwnd = ((MacOSTitlePane) customTitlePane).windowHandle(); - if (hwnd == 0) return new TitlePaneLayoutInfo(new Rectangle(0, 0, -1, -1)); + if (hwnd == 0) { + throw new IllegalStateException( + "Window isn't displayable (but has to in order to compute the title pane layout." + + " If you need this information before the window is displayed call `frame.addNotify()` to make it displayable."); + } float[] b = JNIDecorationsMacOS.windowButtonRect(((MacOSTitlePane) customTitlePane).windowHandle()); return new TitlePaneLayoutInfo(new Rectangle((int) b[0], (int) b[1], (int) b[2], (int) b[3])); } 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 615290da..766ed202 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,7 +200,7 @@ public class MacOSTitlePane extends CustomTitlePane { } public long windowHandle() { - return decorationInformation.windowHandle; + return decorationInformation != null ? decorationInformation.windowHandle : 0; } protected class RootPanePropertyChangeListener implements PropertyChangeListener { diff --git a/platform-decorations/src/main/java/com/github/weisj/darklaf/platform/decorations/NativeDecorationsManager.java b/platform-decorations/src/main/java/com/github/weisj/darklaf/platform/decorations/NativeDecorationsManager.java index 36e8047e..ee0eb820 100644 --- a/platform-decorations/src/main/java/com/github/weisj/darklaf/platform/decorations/NativeDecorationsManager.java +++ b/platform-decorations/src/main/java/com/github/weisj/darklaf/platform/decorations/NativeDecorationsManager.java @@ -119,7 +119,8 @@ public class NativeDecorationsManager { public TitlePaneLayoutInfo titlePaneLayoutInfo(final JRootPane rootPane) { RootPaneUI ui = rootPane.getUI(); - if (!(ui instanceof AbstractNativeDecorationsRootPaneUI)) throw new IllegalStateException(); + if (!(ui instanceof AbstractNativeDecorationsRootPaneUI)) + throw new IllegalStateException("UI is not of type " + AbstractNativeDecorationsRootPaneUI.class); return decorationsProvider.titlePaneLayoutInfo(((AbstractNativeDecorationsRootPaneUI) ui).titlePane()); }