Collapse a node in a JTree?

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)));
}
 
T

Thomas Weidenfeller

Andreas said:
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. [...]
Can you help me?

Reading the JTree API documentation would have helped you much quicker.
Or is there anything wrong with collapsPath()?

BTW, beginner's questions should best go to comp.lang.java.help. Real
GUI questions to comp.lang.java.gui.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top