Window decorations: support enabling/disabling embedding menu bar via UI value at runtime

This commit is contained in:
Karl Tauber
2020-06-28 11:34:30 +02:00
parent 332f05b6e1
commit 6669d0e59d
3 changed files with 12 additions and 3 deletions

View File

@@ -291,7 +291,7 @@ public class FlatRootPaneUI
@Override
public void invalidateLayout( Container parent ) {
if( titlePane != null && titlePane.isMenuBarEmbedded() )
if( titlePane != null )
titlePane.menuBarChanged();
}

View File

@@ -93,7 +93,6 @@ class FlatTitlePane
private final Color inactiveForeground = UIManager.getColor( "TitlePane.inactiveForeground" );
private final Color embeddedForeground = UIManager.getColor( "TitlePane.embeddedForeground" );
private final boolean menuBarEmbedded = UIManager.getBoolean( "TitlePane.menuBarEmbedded" );
private final Insets menuBarMargins = UIManager.getInsets( "TitlePane.menuBarMargins" );
private final Dimension iconSize = UIManager.getDimension( "TitlePane.iconSize" );
private final int buttonMaximizedHeight = UIManager.getInt( "TitlePane.buttonMaximizedHeight" );
@@ -321,7 +320,8 @@ class FlatTitlePane
}
boolean isMenuBarEmbedded() {
return menuBarEmbedded &&
// not storing value of "TitlePane.menuBarEmbedded" in class to allow changing at runtime
return UIManager.getBoolean( "TitlePane.menuBarEmbedded" ) &&
FlatClientProperties.clientPropertyBoolean( rootPane, FlatClientProperties.MENU_BAR_EMBEDDED, true ) &&
FlatSystemProperties.getBoolean( FlatSystemProperties.MENUBAR_EMBEDDED, true );
}

View File

@@ -28,6 +28,7 @@ import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.demo.extras.*;
import com.formdev.flatlaf.demo.intellijthemes.*;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.formdev.flatlaf.ui.JBRCustomDecorations;
import net.miginfocom.swing.*;
/**
@@ -75,6 +76,11 @@ class DemoFrame
private void menuBarEmbeddedChanged() {
getRootPane().putClientProperty( FlatClientProperties.MENU_BAR_EMBEDDED,
menuBarEmbeddedCheckBoxMenuItem.isSelected() ? null : false );
// alternative method for all frames and menu bars in an application
// UIManager.put( "TitlePane.menuBarEmbedded", menuBarEmbeddedCheckBoxMenuItem.isSelected() );
// revalidate();
// repaint();
}
private void underlineMenuSelection() {
@@ -581,6 +587,9 @@ class DemoFrame
cutMenuItem.addActionListener( new DefaultEditorKit.CutAction() );
copyMenuItem.addActionListener( new DefaultEditorKit.CopyAction() );
pasteMenuItem.addActionListener( new DefaultEditorKit.PasteAction() );
menuBarEmbeddedCheckBoxMenuItem.setEnabled( UIManager.getLookAndFeel()
.getSupportsWindowDecorations() || JBRCustomDecorations.isSupported() );
}
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables