选择后如何从JTree中选择节点?

时间:2013-01-17 19:34:05

标签: java swing jtree

  

可能重复:
  JTree: how to get the text of selected item?

1在C#中有TreeView_afterSelect event,我问是否在java中是这样的?我使用过:hierarchyPropertyChange但它运行了两次......

1 个答案:

答案 0 :(得分:7)

您可以使用TreeSelectionListener

tree.addTreeSelectionListener(new TreeSelectionListener() {

@Override
public void valueChanged(TreeSelectionEvent e) {
   DefaultMutableTreeNode selectedNode = 
       (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); 
   ...          
  }
});