Native window decorations: fixed exception when switching Laf after closing a dialog

This commit is contained in:
Karl Tauber
2021-02-22 09:56:40 +01:00
parent b9a2e3ceac
commit e41c91a42b

View File

@@ -59,9 +59,14 @@ public class FlatNativeWindowBorder
if( !isSupported() ) if( !isSupported() )
return null; return null;
// check whether root pane already has a parent, which is the case when switching LaF // Check whether root pane already has a window, which is the case when switching LaF.
// Also check whether the window is displayable, which is required to install
// FlatLaf native window border.
// 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 ); Window window = SwingUtilities.windowForComponent( rootPane );
if( window != null ) { if( window != null && window.isDisplayable() ) {
install( window, FlatSystemProperties.USE_NATIVE_WINDOW_DECORATIONS ); install( window, FlatSystemProperties.USE_NATIVE_WINDOW_DECORATIONS );
return null; return null;
} }
@@ -92,7 +97,7 @@ public class FlatNativeWindowBorder
JFrame frame = (JFrame) window; JFrame frame = (JFrame) window;
// do not enable native window border if JFrame should use system window decorations // do not enable native window border if JFrame should use system window decorations
// and if not forced to use TODO JBR decorations // and if not forced to use FlatLaf/JBR native window decorations
if( !JFrame.isDefaultLookAndFeelDecorated() && if( !JFrame.isDefaultLookAndFeelDecorated() &&
!FlatSystemProperties.getBoolean( systemPropertyKey, false )) !FlatSystemProperties.getBoolean( systemPropertyKey, false ))
return; return;
@@ -111,7 +116,7 @@ public class FlatNativeWindowBorder
JDialog dialog = (JDialog) window; JDialog dialog = (JDialog) window;
// do not enable native window border if JDialog should use system window decorations // do not enable native window border if JDialog should use system window decorations
// and if not forced to use TODO JBR decorations // and if not forced to use FlatLaf/JBR native window decorations
if( !JDialog.isDefaultLookAndFeelDecorated() && if( !JDialog.isDefaultLookAndFeelDecorated() &&
!FlatSystemProperties.getBoolean( systemPropertyKey, false )) !FlatSystemProperties.getBoolean( systemPropertyKey, false ))
return; return;