I have a JPopupMenu attached to two different JTrees. How can a trap the JTree which popped up the Popup menu when the user clicks on the popup menu?

Sandip Chitale

First of all a JPopupMenu can not be added to multiple JTrees. That is because a component can belong to only one hierarchy.

Secondly, "which tree popuped the menu" is really a meaningless question. The popup menu is typically shown in response to a mouse event (isPopupTrigger() == true) on a specific component, in your case a JTree. In doing that you should be adding the JPopupMenu to that JTree anyways. Then when you show the JPopupMenu you could find it's parent i.e. the JTree to which it was added and you know which tree popped it....