How do I double-click a JTree node and get its name?
If I call evt.getSource()
it seems that the object returned is a JTree. I can\'t cast it to a Defa
The following code works for me.
tree.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
// Cast nodeInfo to your object and do whatever you want
}
}
});