Collapse a node in a JTree?

Discussion in 'Java' started by Andreas Wachhold, Jul 16, 2004.

  1. Hello,

    I want to collapse a node from a JTree down its children. I have found
    a nice method that expands a node down its children, but I am stuck at
    collapsing. Here is the expand thing:

    ---
    //expand a single node
    private static void expandSingleNode(
    JTree tree,
    TreeModel data,
    TreePath path) {

    Object node = path.getLastPathComponent();
    int count = data.getChildCount(node);

    //System.out.println(node);

    if (count == 0) {
    if (data.isLeaf(node))
    tree.expandPath(path.getParentPath());
    else
    tree.expandPath(path);
    } else
    for (int i = 0; i < count; i++)
    expandSingleNode(
    tree,
    data,
    path.pathByAddingChild(data.getChild(node, i)));
    }

    ---

    Can you help me?

    Thank you :)
     
    Andreas Wachhold, Jul 16, 2004
    #1
    1. Advertising

  2. Andreas Wachhold wrote:
    > Hello,
    >
    > I want to collapse a node from a JTree down its children. I have found
    > a nice method that expands a node down its children, but I am stuck at
    > collapsing. [...]
    > Can you help me?


    Reading the JTree API documentation would have helped you much quicker.
    Or is there anything wrong with collapsPath()?

    BTW, beginner's questions should best go to comp.lang.java.help. Real
    GUI questions to comp.lang.java.gui.

    /Thomas
     
    Thomas Weidenfeller, Jul 16, 2004
    #2
    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:
    5,949
    Yan-Hong Huang[MSFT]
    Jun 30, 2003
  2. dablick
    Replies:
    2
    Views:
    670
    dablick
    Dec 9, 2003
  3. VVSRKS

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

    VVSRKS, Sep 16, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    202
    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,014
    Tom Castiglia
    Jun 9, 2006
  5. M.L.
    Replies:
    9
    Views:
    300
Loading...

Share This Page