This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Help with refresh on JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Help with refresh on JTree" Watch "Help with refresh on JTree" New topic

Help with refresh on JTree

Roy Anderson

Joined: Oct 22, 2003
Posts: 4
I am having trouble displaying a JTree with newly added nodes.
I have a JTree, inside a JPanel, JScrollPane and JSplitPane.
I create the JTree with a single root node which displays correctly.
I update the JTree with new children which displays correctly.
Using the same exact routine as above - I add additional new children to the root, the new children do not display in the JTree.
I have confirmed that I am using the correct tree and root node in debug that the tree/node objects has been correctly updated. It is just not displaying the new children to the root.
I can expand and collapse the tree which does not show the new children, just the original populated root.
After the root has been updated, I have tried a number of methods to resolve: tree/jpanel/jscrollpane/jsplitpane .revalidate, invalidate, repaint, etc.
I am using v1.4.1.
What am I missing here?
Thanks in advance.
The routine does the following.
public void addNewNode(JTree tree)
TreeModel model = tree.getModel();
SummarySelectNode root = (SummarySelectNode) model.getRoot();
// Create Primary Node add to root
// SummarySelectNode is extended from DefaultMutableTreeNode
SummarySelectNode pNode = new SummarySelectNode();
((DefaultTreeModel) tree.getModel()).nodeChanged(root);
for (int i = 0; i < tree.getRowCount(); i++)
Joe Ess

Joined: Oct 29, 2001
Posts: 9191

Originally posted by At WorkZonie:

What am I missing here?

You are not invoking TreeModel.fireTreeNodesInserted() to tell the TreeModel's listeners that items have been added to the tree model.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Help with refresh on JTree
It's not a secret anymore!