您好,我使用以下代码。每次actionPerformed
调用所选节点都会获得一个新的子节点。然而JTree
,每个节点只显示一个子节点,尽管它有更多。这是为什么?
private class SomeActionListener implements ActionListener{
private DefaultMutableTreeNode _root = new DefaultMutableTreeNode("ROOT");
private JTree _tree;
new SomeActionListener(){
this._tree = new JTree(this._root);
}
@Override
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)_tree.getSelectionPath().getLastPathComponent();
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(e.getWhen());
selectedNode.add(newNode);
}
}