| 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: 1786
|
|
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?
|
 |
 |
|
|
subject: About PopupMenus...
|
|
|