Demo: on macOS use apple.awt.fullWindowContent and apple.awt.transparentTitleBar

This commit is contained in:
Karl Tauber
2022-05-01 11:45:36 +02:00
parent 58b653f55d
commit c3b9dc397d
3 changed files with 30 additions and 0 deletions

View File

@@ -89,6 +89,24 @@ class DemoFrame
// do not use HTML text on macOS
htmlMenuItem.setText( "some text" );
// see https://www.formdev.com/flatlaf/macos/
if( SystemInfo.isMacFullWindowContentSupported ) {
getRootPane().putClientProperty( "apple.awt.fullWindowContent", true );
getRootPane().putClientProperty( "apple.awt.transparentTitleBar", true );
// hide window title
if( SystemInfo.isJava_17_orLater )
getRootPane().putClientProperty( "apple.awt.windowTitleVisible", false );
else
setTitle( null );
// add gap to left side of toolbar
toolBar.add( Box.createHorizontalStrut( 70 ), 0 );
}
// enable full screen mode for this window
getRootPane().putClientProperty( "apple.awt.fullscreenable", true );
}
// integrate into macOS screen menu

View File

@@ -38,6 +38,8 @@ public class FlatLafDemo
public static void main( String[] args ) {
// macOS
if( SystemInfo.isMacOS ) {
// see https://www.formdev.com/flatlaf/macos/
// enable screen menu bar
// (moves menu bar from JFrame window to top of screen)
System.setProperty( "apple.laf.useScreenMenuBar", "true" );
@@ -51,6 +53,7 @@ public class FlatLafDemo
// - "system": use current macOS appearance (light or dark)
// - "NSAppearanceNameAqua": use light appearance
// - "NSAppearanceNameDarkAqua": use dark appearance
// (needs to be set on main thread; setting it on AWT thread does not work)
System.setProperty( "apple.awt.application.appearance", "system" );
}