aspose file tools
The moose likes Swing / AWT / SWT / JFace and the fly likes calling reload method on DefaultTreeModel without closing nodes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "calling reload method on DefaultTreeModel without closing nodes" Watch "calling reload method on DefaultTreeModel without closing nodes" New topic
Author

calling reload method on DefaultTreeModel without closing nodes

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 247
Calling reload() on a DefaultTreeModel object seems to be automatically causing all the nodes in the JTree to be hidden, except for the nodes which are direct descendants of the root node.
My program involves removing nodes and adding nodes to the node structure in the DefaultTreeModel, but the changes in the node structure were not displayed correctly until I added the call to the reload method. But then all the nodes which were open close up automatically. I want a good way to show changes to the node structure without nodes closing.
Michael Dunn
Rancher

Joined: Jun 09, 2003
Posts: 4041
instead of model.reload() try

model.nodeChanged(node)
Ranganathan Kaliyur Mannar
Ranch Hand

Joined: Oct 16, 2003
Posts: 386

You have to call super.fireTreeNodesInserted or super.fireTreeNodesRemoved when you add/remove nodes. This call will leave the opened/closed state of the nodes as it is (and also the current selection as it is).
Call should be like:

where ROOT is the tree root,
parent1, parent2 is the hierarchy
addedIndex is the index of where the child is added to the parent (in this case 'parent2')
and finally the added child object itself.

Same applies for removal. You have to pass the path, removed index and the actual object being removed.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
 
 
subject: calling reload method on DefaultTreeModel without closing nodes
 
Threads others viewed
JTree: How to update nodes?
JTree - Compare Nodes problem
i have a leaf node - it shows expanded handles
maintain action history of drag and drop in jtree
JTree valueChanged() method calling problem
IntelliJ Java IDE