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 / June 2005

Tip: Looking for answers? Try searching our database.

Updating JTree object using the class that implements TreeModelListener

Thread view: 
6tc1@qlink.queensu.ca - 22 Jun 2005 23:31 GMT
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.insertNodeInt­o(childNode,
parentNode,parentNode.getChild­Count())

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;


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.