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

@@ -66,6 +66,9 @@ public class SystemInfo
/** @since 1.1.2 */ public static final boolean isWebswing; /** @since 1.1.2 */ public static final boolean isWebswing;
/** @since 1.1.1 */ public static final boolean isWinPE; /** @since 1.1.1 */ public static final boolean isWinPE;
// features
/** @since 2.3 */ public static final boolean isMacFullWindowContentSupported;
static { static {
// platforms // platforms
String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH ); String osName = System.getProperty( "os.name" ).toLowerCase( Locale.ENGLISH );
@@ -108,6 +111,12 @@ public class SystemInfo
isProjector = Boolean.getBoolean( "org.jetbrains.projector.server.enable" ); isProjector = Boolean.getBoolean( "org.jetbrains.projector.server.enable" );
isWebswing = (System.getProperty( "webswing.rootDir" ) != null); isWebswing = (System.getProperty( "webswing.rootDir" ) != null);
isWinPE = isWindows && "X:\\Windows\\System32".equalsIgnoreCase( System.getProperty( "user.dir" ) ); isWinPE = isWindows && "X:\\Windows\\System32".equalsIgnoreCase( System.getProperty( "user.dir" ) );
// features
// available since Java 12; backported to Java 11.0.8 and 8u292
isMacFullWindowContentSupported =
javaVersion >= toVersion( 11, 0, 8, 0 ) ||
(javaVersion >= toVersion( 1, 8, 0, 292 ) && !isJava_9_orLater);
} }
public static long scanVersion( String version ) { public static long scanVersion( String version ) {

View File

@@ -89,6 +89,24 @@ class DemoFrame
// do not use HTML text on macOS // do not use HTML text on macOS
htmlMenuItem.setText( "some text" ); 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 // integrate into macOS screen menu

View File

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