Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2004

Tip: Looking for answers? Try searching our database.

Custom TreeModel: nodeChanged ?

Thread view: 
Tobias Besch - 11 May 2004 06:47 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.