tags:

views:

161

answers:

2

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?

+4  A: 

By adding something like this into your code:

if (System.getProperty("os.name").contains("Mac")) {
  System.setProperty("apple.laf.useScreenMenuBar", "true");
}
oold
If I run my app with this argument: -Dapple.laf.useScreenMenuBar=true, the bar is shown correctly at the top, but if I do this System.setProperty("apple.laf.useScreenMenuBar", "true"); on the main method, it doesn't. Any ideas?
J. Pablo Fernández
I am not sure. I would try to put it as the first code in main() method or System.setProperty("apple.laf.useScreenMenuBar", "true"); without if condition (is not met if os.name contains "mac" instead of "Mac" for example) It seems to work on my 10.5.8 Leopard.
oold
Yes, I've done both those right away, no if, and in main.
J. Pablo Fernández
+2  A: 

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 describe them.

http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac/

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.

Thorbjørn Ravn Andersen