Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: JTree:如何获取所选项目的文本?
1在 C# 中有TreeView_afterSelect 事件,我问在 java 中是否有类似的东西?我用过:hierarchyPropertyChange但它运行了两次......
hierarchyPropertyChange
您可以使用TreeSelectionListener:
TreeSelectionListener
tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); ... } });