Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get selected node from JTree after selecting it? [duplicate]

Tags:

java

swing

jtree

Possible Duplicate:
JTree: how to get the text of selected item?

1In C# there's TreeView_afterSelect event, and i ask if in java is something like that ? I used : hierarchyPropertyChange but it runs two times...

like image 633
GemHunter1 Avatar asked Feb 17 '23 20:02

GemHunter1


1 Answers

You can use a TreeSelectionListener:

tree.addTreeSelectionListener(new TreeSelectionListener() {

@Override
public void valueChanged(TreeSelectionEvent e) {
   DefaultMutableTreeNode selectedNode = 
       (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 
   ...          
  }
});
like image 165
Reimeus Avatar answered Apr 28 '23 03:04

Reimeus