• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About PopupMenus...

 
Simone Li
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic