我已經成功地掌握了將我的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:
}
}
[從Java訪問Mac OS X的應用程序菜單]的可能重複(http://stackoverflow.com/questions/11734104/access-mac-os-x-application-menu-from-java) – Perception 2013-02-20 20:06:47