简体   繁体   English

在Java中获取OS X App Name菜单

[英]Getting the OS X App Name Menu in Java

I've successfully mastered the ability to move my JMenuBar s to the OS X system menu bar. 我已经成功掌握了将JMenuBar移动到OS X系统菜单栏的功能。 However, when I do this, I am presented with my JMenuBar preceded by both the Apple logo and the name of my app (Say, MyApp ). 但是,当我这样做时,我会看到我的JMenuBar前面是Apple徽标和我的应用程序的名称(Say, MyApp )。 I want to be able to directly access the MyApp menu so that I can add JMenuItem s such as Preferences and Restart. 我希望能够直接访问MyApp菜单,以便我可以添加首选项和重启等JMenuItem How can I access this MyApp menu? 如何访问此MyApp菜单?

Here is my code so far: 到目前为止,这是我的代码:

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:
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM