突出顯示的鏈接是http://www.devdaily.com/blog/post/jfc-swing/handling-main-mac-menu-in-swing-application/但是,Mac OS X下的菜單欄顯示爲包名稱而不是應用程序名稱。我在上面的鏈接中使用代碼沒有任何運氣,所以我不確定最近的Mac OS版本中是否有任何更改。原生Swing菜單欄支持對於MacOS X在Java中
下面是摘錄:
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 2012-07-10 13:24:05
@brendan這是4年前,拜託啊;) – Kezzer 2012-07-10 14:56:45