In a JTree make right click select the node
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ajit_Warrier
Posted On:   Wednesday, February 11, 2004 02:38 PM

How can I make right click select the node in a JTree. I guess I would need to make nodes listen to mouse click, right? How can I do this?

Re: In a JTree make right click select the node

Posted By:   Jaewoong_Choi  
Posted On:   Saturday, March 27, 2004 05:10 AM

do just like this!


(anyway, can u read Korean?)


-------------------------



private JTree jtree;//by member variable for referencing from listener's callback


...
//in some instance method
jtree = new JTree(...);
jtree.addMouseListener(this);


...
//this class must implements MouseListener
//mouseReleased callback implementation
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
TreePath treePath = jtree.getPathForLocation(e.getX(), e.getY());
//U may access jtree reference from here.
//forcely select treePath
jtree.setSelectionPath(treePath);
}
}

About | Sitemap | Contact