up previous next contents
Up: java-on-mac Previous: Identifying that you're running Next: Putting your application name   Contents

Putting the JMenuBar on the Mac menu bar

Now that you know your Java/Swing application is running on the Mac, the next step is to get the menu bar to look like a Mac application. If you do nothing at all your Swing application JMenuBar is going to be on your application's JFrame, as shown Figure 4.1:

Figure 4.1: By default, the JMenuBar is shown on the JFrame.
Image 1-initial

To get the menu bar off the JFrame and onto the Mac menubar, all you need to do is set the system property apple.laf.useScreenMenuBar to true, like this:

System.setProperty("apple.laf.useScreenMenuBar", "true");

Figure 4.2 show that after this one line of code the JMenuBar is now shown on the Mac menu bar for your application:

Figure 4.2: The JMenuBar is now moved to the Mac menu bar.
Image 2-use-apple-menubar