6

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?

Cajunluke
  • 3,103
  • 28
  • 28
Johnydep
  • 6,027
  • 20
  • 57
  • 74
  • Ok if i change the theme to "Aqua" it starts working, so my question should be rather removed and i want to ask how to detect in java, if the underlying OS is MAC?? – Johnydep Apr 24 '12 at 15:47
  • 1
    IMHO, you don't touch look and feel on a Mac. The Aqua theme by Apple is awesome. Apple did it that way that you even don't have to set the look and feel. It will be automatically Aqua instead of Sun Swing Metal. – Martijn Courteaux Apr 24 '12 at 15:48
  • @MartijnCourteaux, true but i am running across problem with the same code running on MAC, when i have explictly set the Look & Feel to "Nimbus", or is it that i will have to remove this assignment?? – Johnydep Apr 24 '12 at 15:50

1 Answers1

7

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.
Cajunluke
  • 3,103
  • 28
  • 28
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287