This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree" Watch "JTree" New topic


Carol Chen

Joined: Jun 10, 2001
Posts: 19
Hi everyone,
I build a swing program with JTree. I don't know how to change the selected node background color when mouse right clicked.
Hope to get the answer soon.
sihem merah

Joined: Aug 07, 2001
Posts: 2
Here is a part of my method mouseClicked(MouseEvent e) in the class implementing MouseListener:
public void mouseClicked(MouseEvent e)
if ((e.getModifiers() & InputEvent.BUTTON3_MASK)== InputEvent.BUTTON3_MASK)
Point pLoc = e.getPoint();
TreePath destPath = tree.getPathForLocation(pLoc.x,pLoc.y);
if (destPath!=null)

It is very easy.
Hope it will help you.
I agree. Here's the link:
subject: JTree