I have successfully mastered the ability to move my JMenuBar to the OS X system JMenuBar . However, when I do this, I am introduced to my JMenuBar , which is preceded by the Apple logo and the name of my application (Say, MyApp ). I want to be able to directly access the MyApp menu to add JMenuItem , such as Settings and Reboot. How can I access this MyApp menu?
Here is my code:
import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; public class Clazz extends JFrame { public Clazz() { setUpGUI(); } private JMenuBar menuBar; private JMenu appMenu; private void setUpGUI() { setUsesSystemMenuBar(true, "MyApp"); if ((menuBar = getJMenuBar()) == null) { menuBar = new JMenuBar(); setJMenuBar(menuBar); } if ((appMenu = getSystemAppMenu()) == null) appMenu = new JMenu(); appMenu.add(new JMenuItem("My Menu Item"); } private void setUsesSystemMenuBar(boolean uses, String appName) { System.setProperty("apple.laf.useScreenMenuBar", Boolean.toString(uses)); if (name != null) System.setProperty("com.apple.mrj.application.apple.menu.about.name", appName.toString());
source share