使用Java获取OS X应用程序名称菜单
我已经成功地掌握了将我的JMenuBar
s移动到OS X系统菜单栏的功能。但是,当我这样做时,我会看到我的JMenuBar
,其前面是Apple徽标和我的应用程序的名称(例如,MyApp)。我希望能够直接访问MyApp菜单,以便我可以添加JMenuItem
,例如“首选项”和“重新启动”。 如何访问此MyApp菜单?使用Java获取OS X应用程序名称菜单
这里是我到目前为止的代码:
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:
}
}
其中的一些可能是过时了一点,但可能会导致正确的道路
感谢...对不起,我想我只是不知道如何进行搜索。你是怎么找到这些的?我尝试了StackOverflow中的'java os x app menu' ...但它似乎没有任何这些 – Supuhstar 2013-02-21 00:02:15
我实际上是在查找“about”菜单,因为我之前已经看过它的内容;) – MadProgrammer 2013-02-21 01:26:02
[从Java访问Mac OS X的应用程序菜单]的可能重复(http://stackoverflow.com/questions/11734104/access-mac-os-x-application-menu-from-java) – Perception 2013-02-20 20:06:47