Mac Java - Make your Java Swing app look like a native Mac app

Just looking through some old code for a Java/Swing editor I started writing years ago, I saw this line of code that I added specifically for the Mac OS X platform:

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

For a Java application running on Mac OS X (a "Mac Java" application), this sets the name of the main menu on the Mac menubar 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 OS X menubar:

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 Mac Java application I'm developing 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 native 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

Mac Java followup

This brief tutorial has been very popular, so I created an even more thorough tutorial on How to make your Java Swing application look and feel like a native Mac application.

Add new comment

The content of this field is kept private and will not be shown publicly.

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.