Auto scroll when a JTree's node expand

Discussion in 'Java' started by Allan Valeriano, Jul 10, 2007.

  1. Hi,

    I have JSplitPane, where the left panel is a JScrollPane with a JTree
    inside, and the right panel is a JTable.

    This is supposed to be something like the windows explorer, where I
    have a tree representing folders on the left and the children listed
    on the right. That way, when I double click a node on the right, the
    node representing it should expand on the tree and get selected.

    This part is working fine, but when I expand a node which is too deep
    in the tree, it gets hidden. I'd like to auto scroll the bar, so the
    selected node would be visible.
    Anybody knows how can I do that? I hope I didn't make it too confusing
    to understand.

    thanks in advance for any help.
     
    Allan Valeriano, Jul 10, 2007
    #1
    1. Advertising

  2. On Jul 10, 7:16 pm, Allan Valeriano <> wrote:
    > This part is working fine, but when I expand a node which is too deep
    > in the tree, it gets hidden. I'd like to auto scroll the bar, so the
    > selected node would be visible.
    > Anybody knows how can I do that? I hope I didn't make it too confusing
    > to understand.


    JTree has a method for this. Read the API documentation.
     
    Hunter Gratzner, Jul 10, 2007
    #2
    1. Advertising

  3. Allan Valeriano

    joel augustine

    Joined:
    May 12, 2012
    Messages:
    1
    Here is the code

    DefaultMutableTreeNode top=new DefaultMutableTreeNode("Table of contents");
    JTree tree = new JTree(top);
    tree.setScrollsOnExpand(true);
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setBounds(as you wish);
    yourcontainer.add(treeView);
     
    joel augustine, May 12, 2012
    #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. Replies:
    0
    Views:
    1,667
  2. dablick
    Replies:
    2
    Views:
    684
    dablick
    Dec 9, 2003
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,519
    Dimitre Novatchev
    Aug 24, 2006
  4. jumpz
    Replies:
    3
    Views:
    649
    Jean-Baptiste Nizet
    Nov 12, 2007
  5. Manoj
    Replies:
    0
    Views:
    581
    Manoj
    Nov 4, 2008
Loading...

Share This Page