本文介绍了克隆整个JTree/TreeModel的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我真的必须自己实现深度克隆吗,还是有任何库方法来获得JTree或TreeModel的深度克隆?
Do i really have to implement the deep-clone myself or are there any library methods to get a deep clone of an JTree or it's TreeModel?
推荐答案
public IndigoMutableTreeNode cloneNode(IndigoMutableTreeNode node){
IndigoMutableTreeNode newNode = new IndigoMutableTreeNode(node.getUserObject());
for(int iChildren=node.getChildCount(), i=0;i<iChildren; i++){
newNode.add((IndigoMutableTreeNode)cloneNode((IndigoMutableTreeNode)node.getChildAt(i) ) );
}
return newNode;
}
只需传递根节点并获得完整的不同根节点,然后将其传递给新树的新模型即可.
Just pass the root node and get the complete different root node and pass it to a new model of new tree.
这篇关于克隆整个JTree/TreeModel的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!