1在C#中有TreeView_afterSelect event,我问是否在java中是这样的?我使用过:hierarchyPropertyChange
但它运行了两次......
答案 0 :(得分:7)
您可以使用TreeSelectionListener
:
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode selectedNode =
(DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
...
}
});