double click in a jtree

C

Christophe Boutin

how to get or what is the event to get the double click on a node of a jtree
i want to add node after a double click
 
C

catalysoft.com

Register a MouseListener with your JTree, and when you receive a MouseEvent
check whether getClickCount() == 2

The JTree is just one component, so you don't register listeners on the
nodes themselves.
Seems like the JavaDoc for JTree already has it covered:
If you are interested in detecting either double-click events or when a user
clicks on a node, regardless of whether or not it was selected, we recommend
you do the following:

final JTree tree = ...;

MouseListener ml = new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
if(selRow != -1) {
if(e.getClickCount() == 1) {
mySingleClick(selRow, selPath);
}
else if(e.getClickCount() == 2) {
myDoubleClick(selRow, selPath);
}
}
}
};
tree.addMouseListener(ml);


Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top