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

416
|
Chapter 11, Native Integration and Packaging
#81 Make Mac Applications Behave Normally
HACK
AWT windows will always use the Mac menu bar.
One thing worth mentioning is that if your application uses different menus
in its various windows, this will still seem strange to Mac users, as the menu
bar will change based on which of your application’s windows has focus.
But to be truly Mac-like, you’d have to have the same menu bar all the time,
which on Windows/Linux might mean having completely inappropriate
menus in some windows. Then again, with good design—and probably
some
ResourceBundles—you should be able to provide an appropriate menu
bar experience to all your users.
Presenting an Appropriate Application Name
On Mac OS X, the first two items (reading left to right) on the menu bar are
the Apple menu, which controls the whole system (Software Update,
Restart, Log Out, etc.), and the Application menu. The Application menu is
meant to contain items relevant to the entire application: an about box, pref-
erences, the ability to hide itself or other applications, and Quit. But the
menu isn’t named Application; instead, it shows the current application’s
name. That’s great for something short and memorable like Mail or Firefox.
But for a Java application, it picks up the name of the application’s
main( )
class. And when you package your code (like you’re supposed to, with the
inverted Internet address style), you get a monstrosity like Figure 11-3.
Fortunately, you can rein in the insanity with the
com.apple.mrj.application.
apple.menu.about.name
property. Just set this to the name you want to show
in the application menu. For example, setting it to MyDemo produces the
much more reasonable application menu seen in Figure 11-4.
Figure 11-3. A long Java classname as a Mac application name

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