Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree

 
Carol Chen
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks
Carol
 
sihem merah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
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)
tree.setSelectionPath(destPath);
}

It is very easy.
Hope it will help you.
Ciao!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic