Refreshing JTree that uses MutableTreeNode and MutableTreeModel

amp834
amp834 used Ask the Experts™
on
I have a JTree  that uses MutableTreeNode and MutableTreeModel, the data comes from a database.  Each Node has a database key "FolderId" that can have subchildren.

I'm writing a right-click menu popup, when the user clicks on a node and selects "Refresh", it deletes the children nodes of that node and re-reads them from the database (in case another user or process has added anything to the database).

I've tried calling various "reload" and "node changed" functions in the tree model, but can't make it show the updated tree on the screen.

Can someone tell me the basic thing that "should" work to refresh the tree?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Java Developer
Top Expert 2010
Commented:
you need to fire the appropriate event from your model, what model class are you using?

Author

Commented:
I'm extending DefaultTreeModel.  Should I call the
fireTreeStructureChanged(Object source, Object[] path, int[] childIndices, Object[] children)
          Notifies all listeners that have registered interest for notification on this event type.

I was under the impression calling nodeStructureChanged should fire the correct events.
      nodeStructureChanged(TreeNode node)
          Invoke this method if you've totally changed the children of node and its childrens children...

[not to mix up several questions, but if it's easy, is there an easy way to get the "+" out of the nodes that don't currently have children?  If it doesn't have children, should I set "it's a leaf"]
Mick BarryJava Developer
Top Expert 2010

Commented:
I'd be using the reload() method but nodeStructureChanged should do the job
can you post how you use it

Author

Commented:
I found the problem.  I had mistakenly put some empty override methods for the "fire change" methods, that were causing the underlying "change" messages not to be sent!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial