• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling reload method on DefaultTreeModel without closing nodes  RSS feed

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of model.reload() try

model.nodeChanged(node)
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!