Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I did not have any Macs so I could not test it; I have used the Nimbus theme as the standard for this project.

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.

It does show the GUI, but sometimes it sticks, or sometimes menus are missing.

Here is a stripped down version of errors shown while launching the 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? Is Nimbus not supported on Mac and if so then what should I use?

like image 208
Johnydep Avatar asked Apr 24 '12 15:04

Johnydep


1 Answers

I wouldn't touch the theme in OS X, it is awesome automatically :D

Just make sure you don't change the theme when you are on 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.
like image 185
Martijn Courteaux Avatar answered Nov 05 '22 18:11

Martijn Courteaux