首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Java中对MacOS X的本机Swing菜单栏支持

Java中对MacOS X的本机Swing菜单栏支持
EN

Stack Overflow用户
提问于 2008-11-20 22:05:27
回答 8查看 21.4K关注 0票数 17

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

下面是一段摘录:

RootGUI() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);(“Hello”);JMenuBar menuBar = new JMenuBar();JMenu file = new JMenu("File");JMenuItem item = new JMenuItem("Woah");file.add(item);menuBar.add(file);setJMenuBar(menuBar);super setSize(100,100);pack();setVisible(true);}

代码语言:javascript
复制
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: " + e.getMessage());
            }
            catch(UnsupportedLookAndFeelException e) {
                System.out.println("UnsupportedLookAndFeelException: " + e.getMessage());
            }

        }
    });
}

菜单栏上的第一个菜单项应该显示为"test",不幸的是情况并非如此。另一方面,文件菜单工作正常。有什么想法吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/307024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档