Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #146

Re: How to auto-expand JT

From "usenet" <usenet@THRWHITE.remove-dii-this>
Subject Re: How to auto-expand JT
Message-ID <1T3kvap9Is4c@uni.chka.de> (permalink)
Newsgroups comp.lang.java.gui
References <Xns9880AF27B8943realhowtowwwrgagnonc@140.99.99.130>
Date 2011-04-27 15:25 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
Real Gagnon <realgagnon+usenet@rgagnon.com> wrote:

> "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

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar


Thread

How to auto-expand JTree "wensa" <wensa@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
  Re: How to auto-expand JT "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
    Re: How to auto-expand JT "wensa" <wensa@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
  Re: How to auto-expand JT "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
  Re: How to auto-expand JT "Real Gagnon" <real.gagnon@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000
    Re: How to auto-expand JT "usenet" <usenet@THRWHITE.remove-dii-this> - 2011-04-27 15:25 +0000

csiph-web