public DefaultMutableTreeNode addObject(DefaultMutableTreeNode parent, Object child, boolean shouldBeVisible) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); if (parent == null) { parent = rootNode; } // It is key to invoke this on the TreeModel, and NOT // DefaultMutableTreeNode int index=parent.getChildCount(); treeModel.insertNodeInto(childNode, parent, index); // Make sure the user can see the lovely new node. if (shouldBeVisible) { tree.scrollPathToVisible(new TreePath(childNode.getPath())); } return childNode; } 为什么我的树只能初始化第一层子节点?帮我看看代码有什么错误
Object child, boolean shouldBeVisible) {
DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child); if (parent == null) {
parent = rootNode;
} // It is key to invoke this on the TreeModel, and NOT
// DefaultMutableTreeNode
int index=parent.getChildCount();
treeModel.insertNodeInto(childNode, parent, index); // Make sure the user can see the lovely new node.
if (shouldBeVisible) {
tree.scrollPathToVisible(new TreePath(childNode.getPath()));
}
return childNode;
}
为什么我的树只能初始化第一层子节点?帮我看看代码有什么错误
自己去看看这个方法,是不是递归调用的
封装child节点,,调用model的方法增加子节点。逻辑简单,也没有什么分支。
请着重考虑一下,你的递归是否正确。递归结束的条件是否正确。
递归,这个函数没有什么递归,从你描述的状况来看还是逻辑控制。你仔细的看看一些逻辑控制的地方有没有问题。