Hi All,
I'm learning Swing.
Googling for "nodeChanged TreeModel" lead me to Sam's article of
9 Sep 1998 07:24:39 GMT in comp.lang.java.gui, where he wrote:
> If you are using the DefaultTreeModel/DefaultMutableTreeNode classes, the
> label
> in the JTree is derived from the toString method of the
> DefaultMutableTreeNode.
> If something would change the result from the toString() method, call
> DefaultTreeModel treeModel;
> DefaultMutableTreeNode theChangedNode;
> ...
> treeModel.nodeChanged(theChangedNode);
> This wil send the necessary events to the listeners of the TreeModel,
> i.e. a.o.
> the JTree internals.
I tried to implement my own TreeModel and added the following methods
among others to it:
public void nodeChanged(Object node) {
this.fireTreeNodesChanged(new TreeModelEvent(
this,
((User) node).getPath()));
}
public void fireTreeNodesChanged(TreeModelEvent e) {
Enumeration listeners = this.treeModelListeners.elements();
while (listeners.hasMoreElements()) {
TreeModelListener listener = (TreeModelListener)
listeners.nextElement();
listener.treeNodesChanged(e);
}
}
The client tree which uses my own implementation of the TreeModel
interface, used to work properly using the DefaultTreeModel.
But after the switch over to my TreeModel, a call of
treeModel.nodeChanged(theChangedNode) doesn't have any effect anymore.
Any ideas what could be wrong?
Kindest Regards,
Tobias
Thomas Weidenfeller - 11 May 2004 08:10 GMT
> Any ideas what could be wrong?
A number of suggestions:
(a) http://www.physci.org/codes/sscce.jsp
(b) Question 5.4 of this group's FAQ
(c) use a debugger to figure out if/when/what event is sent
(d) Study the source of DefaultTreeModel to figure out how
things work there.
/Thomas
Tobias Besch - 11 May 2004 13:41 GMT
Thomas Weidenfeller <nobody@ericsson.invalid> wrote in news:c7pu60$eur$1
@newstree.wise.edt.ericsson.se:
> (d) Study the source of DefaultTreeModel to figure out how
> things work there.
I copied the source code from DefaultTreeModel.
Now it works.
Thank's for all your tipps.
Tobias