一个突出的链接是http://www.devdaily.com/blog/post/jfc-swing/handling-main-mac-menu-in-swing-application/但是Mac OS X下的菜单栏显示为包名称而不是应用程序名称.我正在使用上面链接中的代码而没有任何运气,所以我不确定在最近的Mac OS版本中是否有任何改变.
这是一个摘录:
Run Code Online (Sandbox Code Playgroud)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: " + …Run Code Online (Sandbox Code Playgroud)