I've googled this topic, but does not get a detailed answer.
Thanks in advance!
> 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.
"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