O'Reilly logo

Swing Hacks by Chris Adamson, Joshua Marinacci

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required