我有一个扩展JFrame的Class MainWindow。 在MainWindow我有一个JMenuBar。
我想在OSX上显示MenuBar(Apple符号旁边)。这只适用,当我没有设置物质皮肤。是否可以使用Substance Skin并使用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();
}
答案 0 :(得分:6)
您可以单独指定菜单栏的UI:
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...
}
}
答案 1 :(得分:4)
是的,如下所示。
$ java -Xdock:name=MyApp -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel -jar MyApp.jar