Popup menu

Ok, I added a popup menu item to the ContactList by implementing a Action and calling the addContextMenuListener on the ContactList. My menu item shows up in the popup menu and when I select it, it calls my actionPerformed method… which receives an ActionEvent object.

How do I find out which ContactItem was right clicked on from the event object? I thought I could use the getSource() of the event, but that returns an object of javax.swing.JPopupMenu$1.

The sample in the developer’‘s guide doesn’'t seem to address this.



I found one way to do this. I don’'t particularly like it, but it works. In the poppingUp method of my ContextMenuListener implementation I grab the object that is passed to the method (which is the ContactItem or ContactGroup which was right clicked on) and set it into my Action class. Then when the actionPerformed method gets called on my Action class it has the associated ContactItem/Group.

Seems like there should be a better way to do it.