物质和MacOS MenuBar

| 我有一个扩展JFrame的MainWindow类。 在MainWindow中,我有一个JMenuBar。 我想在OSX顶部(Apple Symbol旁边)显示MenuBar。仅当我未设置物质皮肤时,此方法才有效。是否可以使用物质外观并使用MacOS MenuBar? 我的代码:
//Set Menu for MacOS
System.setProperty(\"apple.laf.useScreenMenuBar\", \"true\");
System.setProperty(\"com.apple.mrj.application.apple.menu.about.name\", name);

try {
    SwingUtilities.invokeAndWait(new Runnable() {  
        public void run() {
            SubstanceSkin skin = new GraphiteGlassSkin();
            SubstanceLookAndFeel.setSkin(skin); //WORKS WHEN I COMMENT THIS (WITHOUT SUBSTANCE SKIN)
            JFrame.setDefaultLookAndFeelDecorated(false);
            MainWindow mainWindow = new MainWindow(name);
            mainWindow.setVisible(true);
        }  
    });
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
    
已邀请:
是的,如下图所示。 $ java -Xdock:name = MyApp -Dswing.defaultlaf = com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel -jar MyApp.jar     
您可以单独指定菜单栏的用户界面,如下所示:
                try {
                    UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
                } catch (UnsupportedLookAndFeelException ex) {
                    // log...
                }

                JMenuBar menubar = frame.getJMenuBar(); // assuming you\'ve set the menu bar already
                String os = System.getProperty(\"os.name\");

                if (os.equals(\"Mac OS X\")) {
                    try {
                        System.setProperty(\"apple.laf.useScreenMenuBar\", \"true\");
                        menubar.setUI((MenuBarUI) Class.forName(\"com.apple.laf.AquaMenuBarUI\").newInstance());
                    } catch (Exception ex) {
                        // log...
                    }
                }
    

要回复问题请先登录注册