• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Right click on JTree?

 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to implement a right click feature on all items in a JTree. When right click on a leaf node, i will display a menu that include "delete" and "Open in new window". What type of listener i need to attach to JTree so it will response to the right click event?
Thanks.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
you just add a MouseListener to your tree and catch the mouseClicked event. Then ask the MouseEvent with isPopUpTrigger() for a right click.
For adding the listener, you can use the MouseAdapter. This class already implemements the MouseListener Interface. You simply overwrite the mouseClicked method.
Hope, this helps
Rene
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic