相关疑难解决方法(0)

原生Swing菜单栏支持MacOS X在Java中

一个突出的链接是http://www.devdaily.com/blog/post/jfc-swing/handling-main-mac-menu-in-swing-application/但是Mac OS X下的菜单栏显示为包名称而不是应用程序名称.我正在使用上面链接中的代码而没有任何运气,所以我不确定在最近的Mac OS版本中是否有任何改变.

这是一个摘录:

public RootGUI() {
    super("Hello");
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("File");
    JMenuItem item = new JMenuItem("Woah");
    file.add(item);
    menuBar.add(file);
    setJMenuBar(menuBar);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(100, 100);
    pack();
    setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
public static void main(String[] args) {
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                System.setProperty("apple.laf.useScreenMenuBar", "true");
                System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Test");
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                new RootGUI();
            }
            catch(ClassNotFoundException e) {
                System.out.println("ClassNotFoundException: " + e.getMessage());
            }
            catch(InstantiationException e) {
                System.out.println("InstantiationException: " + e.getMessage());
            }
            catch(IllegalAccessException e) {
                System.out.println("IllegalAccessException: " + …
Run Code Online (Sandbox Code Playgroud)

java macos swing

16
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×1

macos ×1

swing ×1