Java and Non-Apple L&F

milgner

Registered
Hi everyone,

has anyone tried to use JMenuBar with a non-Apple L&F in Tiger?
If I try to do so (with both JRE 1.4.2 and 1.5), I get a NullPointerException as soon as I try to open a menu:

Code:
apple.awt.EventQueueExceptionHandler Caught Throwable : java.lang.NullPointerException
java.lang.NullPointerException
	at apple.laf.ScreenPopupFactory.getPopup(ScreenPopupFactory.java:38)
	at com.jgoodies.looks.common.ShadowPopupFactory.getPopup(ShadowPopupFactory.java:135)
	at javax.swing.plaf.PopupMenuUI.getPopup(PopupMenuUI.java:44)
	at javax.swing.JPopupMenu.getPopup(JPopupMenu.java:839)
	at javax.swing.JPopupMenu.setVisible(JPopupMenu.java:789)
	at javax.swing.JPopupMenu.show(JPopupMenu.java:956)
	at javax.swing.JMenu.setPopupMenuVisible(JMenu.java:320)
	at javax.swing.JPopupMenu.menuSelectionChanged(JPopupMenu.java:1468)
	at javax.swing.MenuSelectionManager.setSelectedPath(MenuSelectionManager.java:89)
	at javax.swing.plaf.basic.BasicMenuUI.appendPath(BasicMenuUI.java:217)
	at javax.swing.plaf.basic.BasicMenuUI.access$200(BasicMenuUI.java:32)
	at javax.swing.plaf.basic.BasicMenuUI$Handler.mousePressed(BasicMenuUI.java:457)
	at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:221)
	at java.awt.Component.processMouseEvent(Component.java:5559)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
	at java.awt.Component.processEvent(Component.java:5327)
	at java.awt.Container.processEvent(Container.java:2010)
	at java.awt.Component.dispatchEventImpl(Component.java:4029)
	at java.awt.Container.dispatchEventImpl(Container.java:2068)
	at java.awt.Component.dispatchEvent(Component.java:3877)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3933)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
	at java.awt.Container.dispatchEventImpl(Container.java:2054)
	at java.awt.Window.dispatchEventImpl(Window.java:1766)
	at java.awt.Component.dispatchEvent(Component.java:3877)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:267)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Now the question is why apple.laf.ScreenPopupFactory.getPopup() gets called when the laf isn't activated?
If I use Apples L&F, the problem vanishes.

Greetings
Marcus
 
Do other lafs work in general and break only when doing a JmenuBar or do they break when you do something basic like a JFrame with a Jbutton on it?

Just want to make sure you are trying to use an appropriate laf, the last time I remember changing laf it wasn't exactly an elegant process.
 
I've got an application that had no problem with JMenuBar, popup menus, etc. with either the Metal L&F or the Apple L&F. I'm guessing you are doing something unique that isn't quite the norm, but it's hard to tell from just the stack trace. :)
 
I've got tonnes of Java applications that I run daily. None of them exhibit this problem. Perhaps you need to post some code?
 
Hello guys,

thanks for your replies. After some more trying I have come to the conclusion that the problem lies with the JGoodies Plastic3DLookAndFeel. Any other LaF works fine now.
Since it's OSS, I'll try to investigate into the source.
As soon as I find anything, I'll post a followup.

Greetings
Marcus

Edit: I found a quick workaround by calling
com.jgoodies.looks.common.ShadowPopupFactory.uninstall();
 
Glad you found the solution to the problem.

How about running the System look and feel so that the app looks more native? This should be fine on Windows and OS X. On Linux, you might have to use some other L&F as my experience with Swing on Linux has been quite bad.
 
The application in question is to be used on multiple OS by the same users and I want to let the application look the same on all systems.
Additionally, the icons should go with the L&F somewhat, too. That's easier to accomplish with a predefined L&F.
The user can overide the L&F setting with his/her preferred one, though. So if someone likes to use the Windows (or Aqua) L&F, she/he is free to do so.
 
Back
Top