The link from this article is a great tutorial for getting Java applications to integrate with the Mac OS X toolbar and look like a native Mac application.
This is the quick summary in code. The main program looks something like this:
| import com.apple.mrj.*; |
| |
| public static void main(String[] args) { |
| |
| String lcOSName = System.getProperty("os.name").toLowerCase(); |
| boolean IS_MAC = lcOSName.startsWith("mac os x"); |
| |
| if (IS_MAC) { |
| // take the menu bar off the jframe |
| System.setProperty("apple.laf.useScreenMenuBar", "true"); |
| |
| // set the name of the application menu item |
| System.setProperty("com.apple.mrj.application.apple.menu.about.name", "DesktopApp"); |
| |
| // set the look and feel |
| try { |
| UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| } catch (Exception e) { // error processing here |
| } |
| |
| MacOSXController macController = new MacOSXController(); |
| MRJApplicationUtils.registerAboutHandler(macController); |
| MRJApplicationUtils.registerPrefsHandler(macController); |
| MRJApplicationUtils.registerQuitHandler(macController); |
| } |
| launch(DesktopApplication1.class, args); |
| } |
The class MacOSXController is a stub for integrating commands with the application drop down menu:
| import javax.swing.JOptionPane; |
| import com.apple.mrj.MRJAboutHandler; |
| import com.apple.mrj.MRJPrefsHandler; |
| import com.apple.mrj.MRJQuitHandler; |
| |
| public class MacOSXController |
| implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler |
| { |
| public void handleAbout() |
| { |
| JOptionPane.showMessageDialog(null, |
| "about", |
| "about", |
| JOptionPane.INFORMATION_MESSAGE); |
| } |
| |
| public void handlePrefs() throws IllegalStateException |
| { |
| JOptionPane.showMessageDialog(null, |
| "prefs", |
| "prefs", |
| JOptionPane.INFORMATION_MESSAGE); |
| } |
| |
| public void handleQuit() throws IllegalStateException |
| { |
| JOptionPane.showMessageDialog(null, |
| "quit", |
| "quit", |
| JOptionPane.INFORMATION_MESSAGE); |
| // handle exit here |
| // System.exit(0); |
| } |
| } |
| |