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 2005

Tip: Looking for answers? Try searching our database.

JTree.makeVisible() not working for me

Thread view: 
Dave Neuendorf - 02 Nov 2005 16:44 GMT
I'm serializing my JTree expansion state in xml. When my app starts up
and rebuilds the tree, I want to expand any nodes that were visible when
the app last closed. Here is a snippet of code that is supposed to do this:

         DefaultMutableTreeNode childTreeNode = new
DefaultMutableTreeNode();
         int index = treeNode.getChildCount();
         ( ( DefaultTreeModel ) getNavigationTree().getModel()
).insertNodeInto( childTreeNode, treeNode, index );
.........
         Attr visibilityAttribute = nodeElement.getAttributeNode(
"visible" );
         if ( visibilityAttribute != null )
         {
           if ( visibilityAttribute.getValue().equals( "true" ) )
           {
             DefaultTreeModel model = ( DefaultTreeModel )
getNavigationTree().getModel();
             final TreePath path = new TreePath( model.getPathToRoot(
childTreeNode ) );
             Runnable makeVisibleRunnable = new Runnable() { public
void run(){ getNavigationTree().makeVisible( path ); } };
             SwingUtilities.invokeLater( makeVisibleRunnable );
           }
         }

I use invokeLater because this code is being run outside of the event
dispatch thread.

The problem is that the code has no effect. The tree always comes up in
a collapsed state.

Any ideas?

Thanks,
Dave Neuendorf
Dave Neuendorf - 02 Nov 2005 18:23 GMT
I found the problem myself. Elsewhere in my code, after the tree had
been reconstructed, its model.reload() was being called. This, of
course, was collapsing the tree.

Thanks to anyone who was thinking about this for me.

Dave Neuendorf

> I'm serializing my JTree expansion state in xml. When my app starts up
> and rebuilds the tree, I want to expand any nodes that were visible
[quoted text clipped - 33 lines]
> Thanks,
> Dave Neuendorf
Andrew Thompson - 02 Nov 2005 18:40 GMT
...
> Thanks to anyone who was thinking about this for me.

(as one of those people) No worries, you're welcome.

Thanks for having the sense to report the nature of the fix.


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.