Getting the OS X Application Name Menu in Java

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()); //Will put code in for Ubuntu Unity, too, once I figure that out } private JMenu getSystemAppMenu() { //I don't know what to put here! D: } } 
0
source share

Source: https://habr.com/ru/post/1203517/


All Articles