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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top