This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Right click on JTree? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Right click on JTree?" Watch "Right click on JTree?" New topic

Right click on JTree?

SoonAnn Lim
Ranch Hand

Joined: Jun 21, 2001
Posts: 155
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?
Rene Liebmann
Ranch Hand

Joined: May 02, 2002
Posts: 196
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
It is sorta covered in the JavaRanch Style Guide.
subject: Right click on JTree?
Similar Threads
JTree with CheckBox