Making a Java/Swing app look like a Mac app

By Alvin J. Alexander, devdaily.com

Just looking through some old code for a Java/Swing editor I started writing years ago, I saw this line of code:

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

For a Java application running on Mac OS X, this sets the name of the main menu on the Mac menu bar to "WikiTeX", which happens to be the current name of my editor. As I mentioned in an earlier posting, you also need this line of code to put the Java JMenuBar on the Mac menu bar:

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

What the heck, while I'm here I'll cover it all ... if you want the look and feel to be as Mac-like as possible you also need this line of code:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

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:

System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "WikiTeX");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

I'll continue to update this post as I find more tweaks to make Java/Swing applications look and feel more like Mac applications.


FWIW, there's more to do to make a Swing application look and feel like a native Mac OS X application. At the very least you need to handle the "Preferences" and "Quit" menu items properly through callbacks. And in my case, since I use shortcut keys extensively, I need to change all my shortcut keystrokes from using the [Ctrl] to to use the [Apple] key. And then there's also the part about making a Java application launch like a native Mac application.

I'll write more on each of these items as soon as I learn the best ways to deal with them.

Related posts


devdaily logo