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 2006

Tip: Looking for answers? Try searching our database.

How to auto-expand JTree

Thread view: 
wensa - 19 Nov 2006 12:02 GMT
I've googled this topic, but does not get a detailed answer.

Thanks in advance!
Andrew Thompson - 19 Nov 2006 12:29 GMT
> I've googled this topic, but does not get a detailed answer.

How much more detail than 'use a recursive method
to expand the nodes' do you need*?

( * My fees are variable, depending on the detail required. )

Andrew T.
wensa - 19 Nov 2006 14:02 GMT
For example, I want to expand all children of root Node (only the first
level children)

What code can achieve this goal?

Thanks!

> > I've googled this topic, but does not get a detailed answer.
>
[quoted text clipped - 4 lines]
>
> Andrew T.
Andrew Thompson - 19 Nov 2006 14:52 GMT
Please refrain from top-posting.

> For example, I want to expand all children of root Node (only the first
> level children)

> > ( * My fees are variable, depending on the detail required. )

> What code can achieve this goal?

Well... for code, I charge $50 an hour, or part thereof
(but don't worry, that's 'toy' Australian dollars, not
those huge US style dollars).

Andrew T.
Real Gagnon - 19 Nov 2006 22:08 GMT
"wensa" <zhengwt@gmail.com> wrote in news:1163937759.015606.159670
@m7g2000cwm.googlegroups.com:

> I've googled this topic, but does not get a detailed answer.
>
> Thanks in advance!

See http://www.rgagnon.com/javadetails/java-0210.html

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Looking for Java or PB code examples ? Visit Real's How-to  
* http://www.rgagnon.com/howto.html

Christian Kaufhold - 20 Nov 2006 16:50 GMT
> "wensa" <zhengwt@gmail.com> wrote in news:1163937759.015606.159670
> @m7g2000cwm.googlegroups.com:

> > I've googled this topic, but does not get a detailed answer.
> >
> > Thanks in advance!

> See http://www.rgagnon.com/javadetails/java-0210.html

expandAll2Last (silly name?) should read

// assumes 'tree' has a DefaultTreeModel!

public void expandAll2Last(JTree tree)
{
   DefaultTreeModel data = (DefaultTreeModel).getModel();

   DefaultMutableTreeNode root = (DefaultMutableTreeNode)data.getRoot();

   if (root != null)
       tree.scrollPathToVisible(new TreePath(data.getPathToRoot(root.getLastLeaf())));
}

or more generally (untested):

public void expandAll2Last(JTree tree)
{
   TreeModel data = tree.getModel();

   Object node = data.getRoot();

   if (node == null)
       return;

   TreePath p = new TreePath(node);

   while (true)
   {
        int count = data.getChildCount(node);

        if (count == 0)
            break;

        node = data.getChild(node, count - 1);
        p = p.pathByAddingChild(node);
   }

   tree.scrollPathToVisible(p);
}

Also, it is not clear why this method should also scroll, and that it does
not expand the last component (even if not a leaf).

Christian


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.