wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes About PopupMenus... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "About PopupMenus..." Watch "About PopupMenus..." New topic
Author

About PopupMenus...

Simone Li
Greenhorn

Joined: Jul 20, 2009
Posts: 5
I'm attempting to understand how to use popupmenus in my code but I keep getting:

"Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: parent is
null
at java.awt.PopupMenu.show(PopupMenu.java:149)
at PopupMenuTest$PopupListener.maybeShowPopup(PopupMenuTest.java:50)
at PopupMenuTest$PopupListener.mouseReleased(PopupMenuTest.java:45)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:2
90) etc..."

I'm using this to test:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;



Most of it I used actual snippets from java example codes, but it doesn't work!!

Can anyone tell me how to properly use popupmenus? I know I'm missing some crucial detail somewhere.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2180
    
    7
Most of it I used actual snippets from java example codes, but it doesn't work!!


Well then why don't you use the entire example to get it working. Then you remove bits and pieces one at a time if you think its not required and test again until you duplicate the problem.

Also, use the "Code" button to tag the posted code so it is properly formatted. You can edit your original posting to fix it.
Simone Li
Greenhorn

Joined: Jul 20, 2009
Posts: 5
Rob Camick wrote:
Most of it I used actual snippets from java example codes, but it doesn't work!!


Well then why don't you use the entire example to get it working. Then you remove bits and pieces one at a time if you think its not required and test again until you duplicate the problem.

Also, use the "Code" button to tag the posted code so it is properly formatted. You can edit your original posting to fix it.


Hmm... I've just tried adding the popupmenu to the parent component and now it works fine. Which is sorta strange, since the java example didn't add the popupmenu anywhere I can see.

Would you know whether it is necessary or not to add the popupmenu to a component?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: About PopupMenus...