【发布时间】:2010-09-23 08:23:50
【问题描述】:
一个突出的链接是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); }
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());
}
}
});
}
菜单栏上的第一个菜单项应该显示为“测试”,不幸的是,情况并非如此。另一方面,文件菜单工作正常。有什么想法吗?
【问题讨论】:
-
哦,看看所有这些异常
-
@brendan 这是 4 年前的事了,来吧 eh ;)