diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java index 86bc8dc4..291f7c27 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeWindowBorder.java @@ -17,6 +17,7 @@ package com.formdev.flatlaf.ui; import java.awt.Color; +import java.awt.Container; import java.awt.Rectangle; import java.awt.Window; import java.beans.PropertyChangeListener; @@ -24,7 +25,6 @@ import java.util.List; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JRootPane; -import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.event.ChangeListener; import com.formdev.flatlaf.FlatClientProperties; @@ -76,6 +76,11 @@ public class FlatNativeWindowBorder if( !isSupported() ) return null; + // do nothing if root pane has a parent that is not a window (e.g. a JInternalFrame) + Container parent = rootPane.getParent(); + if( parent != null && !(parent instanceof Window) ) + return null; + // Check whether root pane already has a window, which is the case when // switching from another LaF to FlatLaf. // Also check whether the window is displayable, which is required to install @@ -83,9 +88,8 @@ public class FlatNativeWindowBorder // If the window is not displayable, then it was probably closed/disposed but not yet removed // from the list of windows that AWT maintains and returns with Window.getWindows(). // It could be also be a window that is currently hidden, but may be shown later. - Window window = SwingUtilities.windowForComponent( rootPane ); - if( window != null && window.isDisplayable() ) - install( window ); + if( parent instanceof Window && parent.isDisplayable() ) + install( (Window) parent ); // Install FlatLaf native window border, which must be done late, // when the native window is already created, because it needs access to the window. @@ -174,9 +178,9 @@ public class FlatNativeWindowBorder return; // uninstall native window border - Window window = SwingUtilities.windowForComponent( rootPane ); - if( window != null ) - uninstall( window ); + Container parent = rootPane.getParent(); + if( parent instanceof Window ) + uninstall( (Window) parent ); } private static void uninstall( Window window ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java index 7acac163..3cd6156d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JBRCustomDecorations.java @@ -70,9 +70,10 @@ public class JBRCustomDecorations return null; // check whether root pane already has a parent, which is the case when switching LaF - Window window = SwingUtilities.windowForComponent( rootPane ); - if( window != null ) { - FlatNativeWindowBorder.install( window ); + Container parent = rootPane.getParent(); + if( parent != null ) { + if( parent instanceof Window ) + FlatNativeWindowBorder.install( (Window) parent ); return null; } @@ -110,9 +111,9 @@ public class JBRCustomDecorations // since it is actually not possible to uninstall JBR decorations, // simply reduce titleBarHeight so that it is still possible to resize window // and remove hitTestSpots - Window window = SwingUtilities.windowForComponent( rootPane ); - if( window != null ) - setHasCustomDecoration( window, false ); + Container parent = rootPane.getParent(); + if( parent instanceof Window ) + setHasCustomDecoration( (Window) parent, false ); } static boolean hasCustomDecoration( Window window ) {