简体   繁体   English

在Mac上启动时,Swing GUI不会显示或显示错误

[英]Swing GUI does not show or show with errors when launched on Mac

I have a Java Swing project which works fine on both Windows and Ubuntu. 我有一个Java Swing项目,可以在Windows和Ubuntu上正常工作。 I did not have any Macs so I could not test it; 我没有任何Mac,所以我无法测试它; I have used the Nimbus theme as the standard for this project. 我使用Nimbus主题作为该项目的标准。

Now, recently my friend tested the same project both in Eclipse and exported jar, and it is giving errors that do not refer to any specific Java class that I have made. 现在,最近我的朋友在Eclipse和导出的jar中测试了同一个项目,它提供的错误并没有引用我所做的任何特定Java类。

It does show the GUI, but sometimes it sticks, or sometimes menus are missing. 它确实显示了GUI,但有时它会粘住,或者有时菜单丢失。

Here is a stripped down version of errors shown while launching the GUI: 以下是启动GUI时显示的错误版本:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at com.apple.laf.AquaMenuPainter.paintMenuBarBackground(AquaMenuPainter.java:123)
    at com.apple.laf.AquaMenuUI.paintBackground(AquaMenuUI.java:57)
    at com.apple.laf.AquaMenuPainter.paintMenuItem(AquaMenuPainter.java:160)
    at com.apple.laf.AquaMenuUI.paintMenuItem(AquaMenuUI.java:35)
    at javax.swing.plaf.basic.BasicMenuItemUI.paint(BasicMenuItemUI.java:452)
    at javax.swing.plaf.basic.BasicMenuItemUI.update(BasicMenuItemUI.java:448)
    at javax.swing.JComponent.paintComponent(JComponent.java:752)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:34)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)  

Could you tell me what could be the problem, or is there any specific Look and Feel theme I should be using on Mac? 你能告诉我可能是什么问题,还是我应该在Mac上使用任何具体的外观主题? Is Nimbus not supported on Mac and if so then what should I use? Mac上是否不支持Nimbus,如果是,那么我应该使用什么?

I wouldn't touch the theme in OS X, it is awesome automatically :D 我不会触及OS X中的主题,它会自动出色:D

Just make sure you don't change the theme when you are on Mac. 只需确保在使用Mac时不要更改主题。

String osName = System.getProperty("os.name").toLowerCase();
if (!osName.contains("mac")) // if not on mac
{
   // set nimbus
}
// otherwise, do nothing. It goes automatically to Aqua.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM