Substance and MacOS MenuBar
Asked Answered
E

2

5

I have a Class MainWindow which extends JFrame. In MainWindow i have a JMenuBar.

I want to show the MenuBar in OSX on top (next to the Apple Symbol). This only works, when i dont set a Substance Skin. Is it possible to use a Substance Skin and use The MacOS MenuBar?

My Code:

//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();
}
Effervesce answered 16/4, 2011 at 18:10 Comment(0)
S
4

Yes, as shown below.

$ java -Xdock:name=MyApp -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel -jar MyApp.jar
Superbomb answered 16/4, 2011 at 18:33 Comment(2)
See also this series of articles.Superbomb
the link is broken, the article can now be found here without images and here here with imagesDarter
B
6

You can specify the UI for menu bar alone like this:

                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...
                    }
                }
Berl answered 7/11, 2011 at 14:26 Comment(0)
S
4

Yes, as shown below.

$ java -Xdock:name=MyApp -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel -jar MyApp.jar
Superbomb answered 16/4, 2011 at 18:33 Comment(2)
See also this series of articles.Superbomb
the link is broken, the article can now be found here without images and here here with imagesDarter

© 2022 - 2024 — McMap. All rights reserved.