jtree对于指定节点,怎么开启和关闭呢?下面写两个方法,供大家参考。
package com.sysc.xmleditor.utils;
import java.awt.event.MouseEvent;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;
/**
* jtree帮助类
* @author Administrator
*
*/
public class TreeHelp {
/**
* 展开指定节点所有后代节点
* @param aTree展开所有节点,后代节点层层展开
* @param aNode
*/
public static void expandTreeNode(JTree aTree, DefaultMutableTreeNode aNode) {
if (aNode.isLeaf()) {
return;
}
aTree.expandPath(new TreePath( ( (DefaultMutableTreeNode) aNode).getPath()));
int n = aNode.getChildCount();
for (int i = 0; i <n; i++) {
expandTreeNode(aTree, (DefaultMutableTreeNode) aNode.getChildAt(i));
}
}
/**
* 关闭指定节点所有后代节点
* @param aTree,