Hi all, I was previously updating my JTree by using the
JTree.updateUI() method, but this causes exceptions to be thrown as my
application is multi-threaded.
Instead I'm using a custom class that implements TreeModelListener.
Now when I insert a new node into my tree, I use the
DefaultTreeModel.insertNodeInto(childNode,
parentNode,parentNode.getChildCount())
This causes the method treeNodesInserted method in my custom
TreeModelListener to fire.
But from there I don't know what to do to update the display. From
within my custom TreeModelListener method I only have access to the
TreeModelEvent object and I'm not sure how I can use that to update the
JTree's UI.
As it is, my UI does not update - but the above method is getting
fired.
As a work-around I also tried calling JTree.scrollPathToVisible, but
that only creates the first branch of my tree and doesn't create
successive branches.
Thanks for any advice,
Novice
6tc1@qlink.queensu.ca - 23 Jun 2005 01:59 GMT
I'm sure this isn't the right way to do it - but I've found a
work-around - immediately after I call:
DefaultTreeModel.insertNodeInto(childNode,
parentNode,parentNode.getChildCount())
I call:
DefaultTreeModel.reload();
I've read in many places that using the reload method is inefficient -
since this reloads the entire JTree - but I don't know any other way to
refresh the JTree.
Also I'm sure I should be using the event that gets caught in my
Listener to do the reload - but I have no idea how my Listener class
would be able to access the JTree's refresh functionality. Thus now my
Listener is not being used for anything so I can just remove it from my
project.
I've seen a few posts that have shown using the Listener as an inner
class to the class that contains the JTree and DefaultTreeModel object
- thus giving it access to the methods of those two objects. Is making
the Listener an inner class the accepted way of making updates to the
JTree using a custom class that implements TreeModelListener?
Thanks for any advice,
Novice
e01osama - 27 Jun 2005 15:23 GMT
i need to add check box as a leaf of the tree, can i do it. i used
default tree model;