Native Swing Menu Bar Support For MacOS X In Java

后端 未结 7 1993
北海茫月
北海茫月 2020-12-01 09:54

A link that stands out is http://www.devdaily.com/blog/post/jfc-swing/handling-main-mac-menu-in-swing-application/ however the menu bar under Mac OS X displays as the packag

7条回答
  •  情深已故
    2020-12-01 10:29

    @Kezzer

    I think I see what's going on. If you put the main() method in a different class, then everything works. So you need something like:

    public class RootGUILauncher {
      public static void main(String[] args) {
        try {
                    System.setProperty("apple.laf.useScreenMenuBar", "true");
                    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Test");
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            }
            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());
            }
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new RootGUI();
            }
        });
    }
    

    And then put your RootGUI class in a different file.

提交回复
热议问题