2013-02-20 88 views
0

我已經成功地掌握了將我的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: 
    } 
} 
+0

[從Java訪問Mac OS X的應用程序菜單]的可能重複(http://stackoverflow.com/questions/11734104/access-mac-os-x-application-menu-from-java) – Perception 2013-02-20 20:06:47

回答

2
+0

感謝...對不起,我想我只是不知道如何進行搜索。你是怎麼找到這些的?我嘗試了StackOverflow中的'java os x app menu' ...但它似乎沒有任何這些 – Supuhstar 2013-02-21 00:02:15

+0

我實際上是在查找「about」菜單,因爲我之前已經看過它的內容;) – MadProgrammer 2013-02-21 01:26:02

相關問題