Results 1 to 2 of 2
  1. #1
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

    Default JTree not expanding?

    Greetings,

    I have a small method that removes all branches and leaves from a tree and then adds them all again (because one has changed). At the end it should expand the treePath to the leaf that changed, but it doesn't.

    Java Code:
    TreePath openNode = pathToLeaf().getParentPath();
    DefaultTreeModel model = (DefaultTreeModel)myTree.getModel();
    Object root = model.getRoot();
    for (int i=0; i<model.getChildCount(root); i++)
    {
        MutableTreeNode child = (MutableTreeNode)model.getChild(root, i);
        model.removeNodeFromParent(child);
    }
    model.setRoot(null);
    model.setRoot(addToTree(null, new File(installedDir + "/projects")));
    myTree.expandPath(openNode);
    System.out.println(myTree.isExpanded(openNode));
    The addToTree method adds all the branches and leaves back, and works fine, after all the code has finished my tree is all there, laid out properly, but it's all collapsed.

    Even more interestingly, the program returns myTree.isExpanded as true, but it isn't???

    Am I missing something?

    Any help would be appreciated,

    cheers!

  2. #2
    captain alge is offline Member
    Join Date
    Mar 2011
    Posts
    25
    Rep Power
    0

Similar Threads

  1. JPanel shrinking-expanding problem
    By eLancaster in forum New To Java
    Replies: 4
    Last Post: 04-14-2011, 05:48 PM
  2. text areas expanding
    By aizen92 in forum New To Java
    Replies: 5
    Last Post: 03-20-2011, 08:51 PM
  3. JFrame expanding to fit content
    By pcman312 in forum AWT / Swing
    Replies: 1
    Last Post: 12-31-2010, 07:09 PM
  4. Move JTree item to another JTree.
    By Melki in forum AWT / Swing
    Replies: 8
    Last Post: 07-09-2009, 11:59 AM
  5. dynamically expanding byte container?
    By dfens in forum New To Java
    Replies: 1
    Last Post: 07-03-2009, 10:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •