macOS large title bar: added client property FlatClientProperties.MACOS_LARGE_WINDOW_TITLE_BAR (or "FlatLaf.macOS.largeWindowTitleBar")

This commit is contained in:
Karl Tauber
2023-12-12 18:03:38 +01:00
parent 241fe855cc
commit f3be3f2d1c
4 changed files with 38 additions and 12 deletions

View File

@@ -527,6 +527,21 @@ public interface FlatClientProperties
*/
String WINDOW_STYLE_SMALL = "small";
/**
* Specifies whether the window should have a large title bar.
* This adds extra space around the close/minimize/zoom buttons.
* Useful if <a href="https://www.formdev.com/flatlaf/macos/#full_window_content">full window content</a>
* is enabled.
* <p>
* (requires macOS 10.14+, Java 17+ and client property {@code apple.awt.fullWindowContent} set to {@code true})
* <p>
* <strong>Component</strong> {@link javax.swing.JRootPane}<br>
* <strong>Value type</strong> {@link java.lang.Boolean}
*
* @since 3.3
*/
String MACOS_LARGE_WINDOW_TITLE_BAR = "FlatLaf.macOS.largeWindowTitleBar";
//---- JScrollBar / JScrollPane -------------------------------------------

View File

@@ -367,6 +367,21 @@ public class FlatRootPaneUI
if( rootPane.isDisplayable() )
throw new IllegalComponentStateException( "The client property 'Window.style' must be set before the window becomes displayable." );
break;
case FlatClientProperties.MACOS_LARGE_WINDOW_TITLE_BAR:
case "ancestor":
if( SystemInfo.isMacFullWindowContentSupported &&
SystemInfo.isJava_17_orLater &&
rootPane.isDisplayable() &&
FlatClientProperties.clientPropertyBoolean( rootPane, "apple.awt.fullWindowContent", false ) &&
FlatNativeMacLibrary.isLoaded() )
{
Window window = SwingUtilities.windowForComponent( rootPane );
boolean enabled = FlatClientProperties.clientPropertyBoolean( rootPane,
FlatClientProperties.MACOS_LARGE_WINDOW_TITLE_BAR, false );
FlatNativeMacLibrary.setWindowToolbar( window, enabled );
}
break;
}
}

View File

@@ -46,7 +46,6 @@ import com.formdev.flatlaf.icons.FlatAbstractIcon;
import com.formdev.flatlaf.themes.FlatMacDarkLaf;
import com.formdev.flatlaf.themes.FlatMacLightLaf;
import com.formdev.flatlaf.extras.FlatSVGUtils;
import com.formdev.flatlaf.ui.FlatNativeMacLibrary;
import com.formdev.flatlaf.util.ColorFunctions;
import com.formdev.flatlaf.util.FontUtils;
import com.formdev.flatlaf.util.LoggingFacade;
@@ -90,21 +89,23 @@ class DemoFrame
// do not use HTML text in menu items because this is not supported in macOS screen menu
htmlMenuItem.setText( "some text" );
JRootPane rootPane = getRootPane();
if( SystemInfo.isMacFullWindowContentSupported ) {
// expand window content into window title bar and make title bar transparent
getRootPane().putClientProperty( "apple.awt.fullWindowContent", true );
getRootPane().putClientProperty( "apple.awt.transparentTitleBar", true );
rootPane.putClientProperty( "apple.awt.fullWindowContent", true );
rootPane.putClientProperty( "apple.awt.transparentTitleBar", true );
rootPane.putClientProperty( FlatClientProperties.MACOS_LARGE_WINDOW_TITLE_BAR, true );
// hide window title
if( SystemInfo.isJava_17_orLater )
getRootPane().putClientProperty( "apple.awt.windowTitleVisible", false );
rootPane.putClientProperty( "apple.awt.windowTitleVisible", false );
else
setTitle( null );
}
// enable full screen mode for this window (for Java 8 - 10; not necessary for Java 11+)
if( !SystemInfo.isJava_11_orLater )
getRootPane().putClientProperty( "apple.awt.fullscreenable", true );
rootPane.putClientProperty( "apple.awt.fullscreenable", true );
}
// integrate into macOS screen menu
@@ -902,10 +903,10 @@ class DemoFrame
// JFormDesigner - End of component initialization //GEN-END:initComponents
backButton.addActionListener( e -> {
FlatNativeMacLibrary.setWindowToolbar( this, true );
rootPane.putClientProperty( FlatClientProperties.MACOS_LARGE_WINDOW_TITLE_BAR, true );
});
forwardButton.addActionListener( e -> {
FlatNativeMacLibrary.setWindowToolbar( this, false );
rootPane.putClientProperty( FlatClientProperties.MACOS_LARGE_WINDOW_TITLE_BAR, null );
});
cutButton.addActionListener( e -> System.out.println( e ) );

View File

@@ -27,7 +27,6 @@ import com.formdev.flatlaf.fonts.inter.FlatInterFont;
import com.formdev.flatlaf.fonts.jetbrains_mono.FlatJetBrainsMonoFont;
import com.formdev.flatlaf.fonts.roboto.FlatRobotoFont;
import com.formdev.flatlaf.fonts.roboto_mono.FlatRobotoMonoFont;
import com.formdev.flatlaf.ui.FlatNativeMacLibrary;
import com.formdev.flatlaf.util.SystemInfo;
/**
@@ -118,10 +117,6 @@ public class FlatLafDemo
// show frame
frame.pack();
frame.setLocationRelativeTo( null );
if( SystemInfo.isMacOS && FlatNativeMacLibrary.isLoaded() ) {
// TODO use client property
FlatNativeMacLibrary.setWindowToolbar( frame, true );
}
frame.setVisible( true );
} );
}