Tree 检索数据是在TreeModel中作的。
getRoot()
getChildCount();
getChild();
...
getRoot()
getChildCount();
getChild();
...
解决方案 »
- 新年好!关于JAVA多文档窗口的问题!
- 高分请教面试问题.........
- 为什么设置了jdbc connector的路径,拷到了jre下面,java程序还是无法连接到数据库?谢谢各位大虾了
- 声明 初始化问题
- 关于applet的问题请教!
- 如何把java.math.BigDecimal类型后面多余的零(0)去掉?
- 请教高手,如何用正则表达式匹配同时出现的多个单词?
- eclipse有没有象PasswordField这样的TextField Component?
- --=如何使我的jtree的node中一部分是可编辑的,而另外一些是不可编辑的?=--
- HELP!!!!!!!!!!!有关TOMCAT
- 容器
- 变量隐藏。是一种什么概念?给个例子把
不是数据结构中的树!
问题是子树下面又有孙树,可能是一种递归的情况,有没有好用的代码?
宽度优先
Enumeration enumeration = currentNode.breadthFirstEnumeration();
深度优先
Enumeration enumeration = currentNode.depthFirstEnumeration();
使用这两个方法可以得到他的所有子孙节点
Returns the children of the receiver as an Enumeration.
boolean getAllowsChildren()
Returns true if the receiver allows children.
TreeNode getChildAt(int childIndex)
Returns the child TreeNode at index childIndex.
int getChildCount()
Returns the number of children TreeNodes the receiver contains.
int getIndex(TreeNode node)
Returns the index of node in the receivers children.
TreeNode getParent()
Returns the parent TreeNode of the receiver.
boolean isLeaf()
Returns true if the receiver is a leaf.
Vector returnChildNode(DefaultMutableTreeNode currNode){
hs.add(currNode);
int childCount currNode.getChildCount();
for(int i=0;i<childCount;i++){
returnChildNode((DefaultMutableTreeNode)currNode.getChildAt(i));
}
}