to jackkui 看了这个例子我知道了2、3操作的方法,但是我还是不知道怎么才能得到树的根结点呀,希望能有好心人告诉我,急!
用JTree里面的getModel得到JTree得Model /** * Returns the <code>TreeModel</code> that is providing the data. * * @return the <code>TreeModel</code> that is providing the data */ public TreeModel getModel() { return treeModel; } 得到根节点用 interface TreeModel里的 /** * Returns the root of the tree. Returns <code>null</code> * only if the tree has no nodes. * * @return the root of the tree */ public Object getRoot(); 至于每一个节点的你要自己实现TreeNode接口。 作一个加子节点的方法,在每次加完之后,调用TreeModle里面的 /** * Invoke this method if you've modified the TreeNodes upon which this * model depends. The model will notify all of its listeners that the * model has changed below the node <code>node</code> (PENDING). */ public void reload(TreeNode node) ;
/**
* Returns the <code>TreeModel</code> that is providing the data.
*
* @return the <code>TreeModel</code> that is providing the data
*/
public TreeModel getModel() {
return treeModel;
}
得到根节点用 interface TreeModel里的
/**
* Returns the root of the tree. Returns <code>null</code>
* only if the tree has no nodes.
*
* @return the root of the tree
*/
public Object getRoot();
至于每一个节点的你要自己实现TreeNode接口。
作一个加子节点的方法,在每次加完之后,调用TreeModle里面的
/**
* Invoke this method if you've modified the TreeNodes upon which this
* model depends. The model will notify all of its listeners that the
* model has changed below the node <code>node</code> (PENDING).
*/
public void reload(TreeNode node) ;