3 December 2007

Developing Mac-friendly Java applications

Macintosh applications have a different visual appearance than Windows' and one obvious difference is the application's menu, which is placed on the top bar of Mac OS X instead of the title bar of the application's window.

However, developing Java applications using Swing as the library for the graphical user interface will default to the Windows behavior where the menu is placed on the application's window. For Mac users this behavior will differ from what they're used to and might difficult their adaptation to the application's GUI.

If you're a Java developer and the target users of your applications are using Macintosh, then this tip is for you. In order to get the menu to be displayed on the Mac OS X top bar, all you have to do is add this line of code before you initiate your JFrame in your main class:

System.setProperty("apple.laf.useScreenMenuBar", "true");
The good thing about this change in the code is that other systems will just ignore this and the menu-bar will appear as normal for that system.

Source: David Winter's Blog

No comments: