Swing GUI not showing or showing errors on launch on Mac

I have a Java Swing project that works great on both Windows and Ubuntu. I did not have any Macs, so I could not verify this; I used the Nimbus theme as the standard for this project.

My friend recently tested the same project in both Eclipse and exported jar, and it gives errors that do not apply to any specific Java class that I made.

It shows a graphical interface, but sometimes it is stored, or sometimes the menu is missing.

Here is the version of errors displayed when starting 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 might be the problem, or is there any specific Look and Feel theme that I should use on a Mac? Nimbus is not supported on Mac, and if so, what should I use?

+6
source share
1 answer

I would not touch on the topic in OS X, it is amazing automatically: D

Just make sure you don’t change the theme when you are on a 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. 
+7
source

Source: https://habr.com/ru/post/914049/


All Articles