Java中对MacOS X的本机Swing菜单栏支持

Java中对MacOS X的本机Swing菜单栏支持,第1张

Java中对MacOS X的本机Swing菜单栏支持

@凯泽

我想我知道发生了什么事。如果将main()方法放在 另一个类中 ,则一切正常。因此,您需要类似:

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();        }    });}

然后将您的RootGUI类放在另一个文件中。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5032000.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存