使用Java获取OS X应用程序名称菜单 [英] Getting the OS X App Name Menu in Java

查看:105
本文介绍了使用Java获取OS X应用程序名称菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功掌握了将JMenuBar移至OS X系统菜单栏的功能.但是,当我这样做时,会在我的JMenuBar前面出现Apple徽标和我的应用程序名称(例如, MyApp ).我希望能够直接访问 MyApp 菜单,以便添加JMenuItem,例如首选项"和重新启动". 如何访问此 MyApp 菜单?

I've successfully mastered the ability to move my JMenuBars to the OS X system menu bar. 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). I want to be able to directly access the MyApp menu so that I can add JMenuItems such as Preferences and Restart. How can I access this MyApp menu?

到目前为止,这是我的代码:

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

推荐答案

其中一些可能有些过时,但可能会导致正确的道路

Some of these might be a little out of date, but may lead down the right path

  • Access Mac OS X Application Menu from Java
  • "Bringing my Java application to Mac OS X": Menus
  • Java OS X Lion About Menu
  • OSX integration for Java

这篇关于使用Java获取OS X应用程序名称菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆