A
Andreas Wachhold
Hello,
I want to collapse a node from a JTree down its children. I have found
a nice method that expands a node down its children, but I am stuck at
collapsing. Here is the expand thing:
---
//expand a single node
private static void expandSingleNode(
JTree tree,
TreeModel data,
TreePath path) {
Object node = path.getLastPathComponent();
int count = data.getChildCount(node);
//System.out.println(node);
if (count == 0) {
if (data.isLeaf(node))
tree.expandPath(path.getParentPath());
else
tree.expandPath(path);
} else
for (int i = 0; i < count; i++)
expandSingleNode(
tree,
data,
path.pathByAddingChild(data.getChild(node, i)));
}
I want to collapse a node from a JTree down its children. I have found
a nice method that expands a node down its children, but I am stuck at
collapsing. Here is the expand thing:
---
//expand a single node
private static void expandSingleNode(
JTree tree,
TreeModel data,
TreePath path) {
Object node = path.getLastPathComponent();
int count = data.getChildCount(node);
//System.out.println(node);
if (count == 0) {
if (data.isLeaf(node))
tree.expandPath(path.getParentPath());
else
tree.expandPath(path);
} else
for (int i = 0; i < count; i++)
expandSingleNode(
tree,
data,
path.pathByAddingChild(data.getChild(node, i)));
}