Demo on Linux: support toggling FlatLaf window decorations (menu "Options > Window decorations")

This commit is contained in:
Karl Tauber
2025-03-23 13:58:02 +01:00
parent 835a1f155b
commit 23f8ce867b

View File

@@ -228,8 +228,20 @@ class DemoFrame
private void windowDecorationsChanged() { private void windowDecorationsChanged() {
boolean windowDecorations = windowDecorationsCheckBoxMenuItem.isSelected(); boolean windowDecorations = windowDecorationsCheckBoxMenuItem.isSelected();
// change window decoration of all frames and dialogs if( SystemInfo.isLinux ) {
FlatLaf.setUseNativeWindowDecorations( windowDecorations ); // enable/disable custom window decorations
JFrame.setDefaultLookAndFeelDecorated( windowDecorations );
JDialog.setDefaultLookAndFeelDecorated( windowDecorations );
// dispose frame, update decoration and re-show frame
dispose();
setUndecorated( windowDecorations );
getRootPane().setWindowDecorationStyle( windowDecorations ? JRootPane.FRAME : JRootPane.NONE );
setVisible( true );
} else {
// change window decoration of all frames and dialogs
FlatLaf.setUseNativeWindowDecorations( windowDecorations );
}
menuBarEmbeddedCheckBoxMenuItem.setEnabled( windowDecorations ); menuBarEmbeddedCheckBoxMenuItem.setEnabled( windowDecorations );
unifiedTitleBarMenuItem.setEnabled( windowDecorations ); unifiedTitleBarMenuItem.setEnabled( windowDecorations );
@@ -486,7 +498,7 @@ class DemoFrame
} }
private boolean supportsFlatLafWindowDecorations() { private boolean supportsFlatLafWindowDecorations() {
return FlatLaf.supportsNativeWindowDecorations() || (SystemInfo.isLinux && JFrame.isDefaultLookAndFeelDecorated()); return FlatLaf.supportsNativeWindowDecorations() || SystemInfo.isLinux;
} }
private void initComponents() { private void initComponents() {
@@ -979,10 +991,9 @@ class DemoFrame
scrollingPopupMenu.add( "Item " + i ); scrollingPopupMenu.add( "Item " + i );
if( supportsFlatLafWindowDecorations() ) { if( supportsFlatLafWindowDecorations() ) {
if( SystemInfo.isLinux ) windowDecorationsCheckBoxMenuItem.setSelected( SystemInfo.isLinux
unsupported( windowDecorationsCheckBoxMenuItem ); ? JFrame.isDefaultLookAndFeelDecorated()
else : FlatLaf.isUseNativeWindowDecorations() );
windowDecorationsCheckBoxMenuItem.setSelected( FlatLaf.isUseNativeWindowDecorations() );
menuBarEmbeddedCheckBoxMenuItem.setSelected( UIManager.getBoolean( "TitlePane.menuBarEmbedded" ) ); menuBarEmbeddedCheckBoxMenuItem.setSelected( UIManager.getBoolean( "TitlePane.menuBarEmbedded" ) );
unifiedTitleBarMenuItem.setSelected( UIManager.getBoolean( "TitlePane.unifiedBackground" ) ); unifiedTitleBarMenuItem.setSelected( UIManager.getBoolean( "TitlePane.unifiedBackground" ) );
showTitleBarIconMenuItem.setSelected( UIManager.getBoolean( "TitlePane.showIcon" ) ); showTitleBarIconMenuItem.setSelected( UIManager.getBoolean( "TitlePane.showIcon" ) );
@@ -1026,7 +1037,7 @@ class DemoFrame
private void unsupported( JCheckBoxMenuItem menuItem ) { private void unsupported( JCheckBoxMenuItem menuItem ) {
menuItem.setEnabled( false ); menuItem.setEnabled( false );
menuItem.setSelected( false ); menuItem.setSelected( false );
menuItem.setToolTipText( "Not supported on your system." ); menuItem.setToolTipText( "Not supported on this platform." );
} }
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables