up previous next contents
Up: java-on-mac Previous: Putting the JMenuBar on Next: Converting Control keystrokes to   Contents

Putting your application name on the menu bar

Now that the JMenuBar is in the right place, we need to change the name of the first menu in the menu bar (the application menu). If you don't give it a name, it will show the name of your Java class in the place where a Mac application's name is normally shown, which is a no-op for me.

All you have to do to set the menu item name to show your application's name is to add another system property setting:

System.setProperty("com.apple.mrj.application.apple.menu.about.name", "WikiTeX");

Figure 5.1 shows that this sets the name of the main menu on the Mac menu bar to "WikiTeX", which is the name of my Java/Swing text editor.

Figure 5.1: My application name ("WikiTeX") is now shown in the Mac menu bar.
Image 3-use-screen-about-name

Important note: I was very surprised to learn that the call to set the system look and feel needs to be made after the call to set the application name. If the calls are reversed the application menu shows the Java class name once again.

So, in total, the Java/Swing application I'm developing primarily for use on a Mac OS X system has these three lines of initialization code:

// take the menu bar off the jframe
System.setProperty("apple.laf.useScreenMenuBar", "true");

// set the name of the application menu item
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "WikiTeX");

// set the look and feel
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());