Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JTree not expanding?

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Location
    England
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

    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,

    P.S. Sorry if this is in the wrong section, I wasn't sure if I should post it here or in the Swing section

    cheers!


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: JTree not expanding?

    Hello captain alge.

    Welcome to the Java Programming Forums.

    Interesting username you have there lol

    I have moved this thread to the AWT / Java Swing forum.

    Could you post all of your code please? I would like to compile it and take a look..
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Replies: 0
    Last Post: February 14th, 2011, 05:10 AM
  2. JTree - Remove All Nodes
    By aussiemcgr in forum Java Theory & Questions
    Replies: 4
    Last Post: December 9th, 2010, 04:27 PM
  3. [SOLVED] Jtree help
    By sman36 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 6th, 2010, 08:39 AM
  4. Expanding JTextArea
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 27th, 2010, 09:15 PM
  5. Expanding the capacity of an array
    By dubois.ford in forum Collections and Generics
    Replies: 5
    Last Post: May 7th, 2010, 05:58 AM