gpt4 book ai didi

java - 使用Java获取OS X应用程序名称菜单

转载 作者:行者123 更新时间:2023-12-02 07:15:24 27 4
gpt4 key购买 nike

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

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

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 - 使用Java获取OS X应用程序名称菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14988628/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com