JTree will expand but not collapse

Discussion in 'Java' started by dablick, Dec 9, 2003.

  1. dablick

    dablick Guest

    I'm trying to write some buttons that entirely expand and entirely collapse
    a JTree and would appreciate any help.

    For some reason, the code I have will expand the tree, but not collapse it.

    Here's the basic recursive tree walking function I use to do it. Why does
    it only for the expand case and not the collapse case?

    void walk_subtree(TreeNode n, boolean expand) {

    Enumeration e = n.children();

    while (e.hasMoreElements()) {
    DefaultMutableTreeNode c = (DefaultMutableTreeNode)
    e.nextElement();
    TreePath tp = cvt2(c);

    if (expand) {
    jTree1.expandPath(tp);
    }
    else {
    jTree1.collapsePath(tp);
    }

    walk_subtree(c, expand);
    }
    }
     
    dablick, Dec 9, 2003
    #1
    1. Advertising

  2. dablick <> wrote:

    > I'm trying to write some buttons that entirely expand and entirely collapse
    > a JTree and would appreciate any help.
    >
    > For some reason, the code I have will expand the tree, but not collapse it.
    >
    > Here's the basic recursive tree walking function I use to do it. Why does
    > it only for the expand case and not the collapse case?



    collapsePath also expands the parent path of the path to collapse.

    Use post-order walk for collapsePath.



    Christian
     
    Christian Kaufhold, Dec 9, 2003
    #2
    1. Advertising

  3. dablick

    dablick Guest

    Yep. That was it.

    Thanks,

    db

    "Christian Kaufhold" <> wrote in message
    news:...
    > dablick <> wrote:
    >
    > > I'm trying to write some buttons that entirely expand and entirely

    collapse
    > > a JTree and would appreciate any help.
    > >
    > > For some reason, the code I have will expand the tree, but not collapse

    it.
    > >
    > > Here's the basic recursive tree walking function I use to do it. Why

    does
    > > it only for the expand case and not the collapse case?

    >
    >
    > collapsePath also expands the parent path of the path to collapse.
    >
    > Use post-order walk for collapsePath.
    >
    >
    >
    > Christian
     
    dablick, Dec 9, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vaclav Jedlicka

    datagrid and border-collapse:collapse style

    Vaclav Jedlicka, Jun 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    6,044
    Yan-Hong Huang[MSFT]
    Jun 30, 2003
  2. Andreas Wachhold

    Collapse a node in a JTree?

    Andreas Wachhold, Jul 16, 2004, in forum: Java
    Replies:
    1
    Views:
    1,311
    Thomas Weidenfeller
    Jul 16, 2004
  3. VVSRKS

    How can I avoid border-collapse:collapse to come ...

    VVSRKS, Sep 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    225
    VVSRKS
    Sep 16, 2004
  4. Tom Castiglia

    Why does Gridview ALWAYS emit style="border-collapse: collapse;"

    Tom Castiglia, Jun 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    2,198
    Tom Castiglia
    Jun 9, 2006
  5. M.L.
    Replies:
    9
    Views:
    321
Loading...

Share This Page