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