Question

In the Java Desktop Application template used by Netbeans, a menu bar is created with JMenuBar and JMenuItems.

How can I get that bar displayed at the top, where menu bars are displayed in MacOSX instead of in-window, like in Windows?

Was it helpful?

Solution

Note: This is outdated information - a more recent answer is needed.

Java applications look like traditional java applications even under OS X.

If you want a native look and feel, there are a few tweaks you have to do. This article series describes them.

http://www.oracle.com/technetwork/articles/javase/javatomac-140486.html http://www.oracle.com/technetwork/java/javatomac2-138389.html

This includes setting the Dock icon and text, and integrating with the Applications menu.

I believe that the OS X "wrap jar as an application" utility with XCode sets all these properties automatically.

OTHER TIPS

By adding something like this into your code:

if (System.getProperty("os.name").contains("Mac")) {
  System.setProperty("apple.laf.useScreenMenuBar", "true");
}

I had the same issue, but I realized that the MenuBar needs to be added to the frame as:

frame.setJMenuBar(menuBar);

instead of: frame.add(jMenuBar); along with: System.setProperty("apple.laf.useScreenMenuBar", "true"); in the main method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top