Make Mac Applications Behave Normally #81
Chapter 11, Native Integration and Packaging
|
415
HACK
Using the Mac’s Menu Bar
One of the most striking differences between the Mac and Windows/Linux
GUIs is that the Mac has a single menu bar at the top of the screen, rather
than menu bars in each application window. This will break a lot of assump-
tions if you’re coming over from the Windows world (for one thing, an
application can still be running without any windows open, since the user
can usually spawn a new window from the File menu), but for now, just
focus on the fact that menus inside of windows are going to feel very alien to
a Mac user. Figure 11-1 shows what a typical Swing window looks like on a
Mac with the menu bar in the window.
Change that by setting the system property
apple.laf.useScreenMenuBar to
true. This takes all Swing menu bars out of their JFrames and puts them up
in the Mac menu bar. Figure 11-2 shows the effect of setting this property on
a Swing window.
Figure 11-1. Swing application with menu bar in a Mac window
Figure 11-2. Swing application with menus in a Mac menu bar

Get Swing Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.