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 / November 2004

Tip: Looking for answers? Try searching our database.

Updating of a Tree when the label changes

Thread view: 
Deborah K. Charan - 28 Oct 2004 14:11 GMT
I have seen postings about similar problems, and have tried
duplicating what others have tried, but my tree never updates with the
new values.  In the code below, I have stepped through and see the new
nodes with the correct values, but it never redraws.  The reason that
I am removing and reinserting the node is that just calling
node.setUserObject(newVal) does not change the length of the label.
Atleast it updates the label to ... :)

Here is the code snipet.  If I don't actually expand the tree until
later in the game, I do get the current value for SysUpTime and
numPktsRecvd, but it never updates it from there.

        if (label == "SysUpTime")
            node = _sysUpTime;
        else if (label == "Packets Received")
            node = _numPktsRecvd;

        DefaultMutableTreeNode newNode;
        TreeNode parent = node.getParent();
        int index = parent.getIndex(node);
        _localModel.removeNodeFromParent(node);
        newNode = new DefaultMutableTreeNode(
                new String(label + ":    " + value), false);
        _localModel.insertNodeInto((MutableTreeNode) newNode,
                (MutableTreeNode) parent, index);
        if (label == "SysUpTime")
            _sysUpTime = newNode;
        else if (label == "Packets Received")
            _numPktsRecvd = newNode;
        _localModel.reload();

Any information would be appreciated.

Thanks
Debbie Charan
Babu Kalakrishnan - 28 Oct 2004 14:59 GMT
> I have seen postings about similar problems, and have tried
> duplicating what others have tried, but my tree never updates with the
[quoted text clipped - 3 lines]
> node.setUserObject(newVal) does not change the length of the label.
> Atleast it updates the label to ... :)

Are you doing the removal / insertion in a thread different from the EDT ?

BK
Deborah K. Charan - 29 Oct 2004 18:07 GMT
The insertion/deletion is happenning in a different thread than the
tree was originally created in.  It is only modified within that
thread within a loop.  Whenever I have data to update, I want to
change the tree.  Within the loop I check if the data has been
changed.

BTW, what does EDT stand for?

> > I have seen postings about similar problems, and have tried
> > duplicating what others have tried, but my tree never updates with the
[quoted text clipped - 7 lines]
>
> BK
Babu Kalakrishnan - 01 Nov 2004 08:14 GMT
[Moving top posted response below]

>>>I have seen postings about similar problems, and have tried
>>>duplicating what others have tried, but my tree never updates with the
[quoted text clipped - 5 lines]
>>
>>Are you doing the removal / insertion in a thread different from the EDT ?

> The insertion/deletion is happenning in a different thread than the
> tree was originally created in.  It is only modified within that
> thread within a loop.  Whenever I have data to update, I want to
> change the tree.  Within the loop I check if the data has been
> changed.

All interactions with swing GUI objects must be done in the AWT Event
Dispatch Thread, or else the views may not update.

Read the Java Tutorial section of Swing and thread safety for details.
You need to use the SwingUtilities.invokeLater wrapper around your calls
 that update the GUI to move them to the EDT.

> BTW, what does EDT stand for?

The Event Dispatch Thread.

BK

PS : Please do not top post. It is very confusing for other readers to
see a response on top and the problem description further down.


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.