Tree 检索数据是在TreeModel中作的。
getRoot()
getChildCount();
getChild();
...

解决方案 »

  1.   

    可能是我表达的有问题,我是用JTree做了一个树,现在用鼠标点击其中的一个节点,我想得到所有这个被点击节点的子孙节点,请问怎么做?
    不是数据结构中的树!
      

  2.   

    谢谢WQmeng(*耶*) 。
    问题是子树下面又有孙树,可能是一种递归的情况,有没有好用的代码?
      

  3.   

    DefaultMutableTreeNode currentNode;
    宽度优先
    Enumeration enumeration = currentNode.breadthFirstEnumeration();
    深度优先
    Enumeration enumeration = currentNode.depthFirstEnumeration();
    使用这两个方法可以得到他的所有子孙节点
      

  4.   

    Enumeration children() 
              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. 
      

  5.   

    Vector hs = new Vector ();
    Vector returnChildNode(DefaultMutableTreeNode currNode){
      hs.add(currNode);
      int childCount currNode.getChildCount();
      for(int i=0;i<childCount;i++){
        returnChildNode((DefaultMutableTreeNode)currNode.getChildAt(i));
      }
    }