Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #2660

JTree, updating model and

From "Florent Georges" <florent.georges@THRWHITE.remove-dii-this>
Subject JTree, updating model and
Message-ID <1192627853.057329.100920@y27g2000pre.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:40 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
  Hi

  I am discovering the Swing's tree API.  I am building a
tree one node after the other (the nodes reflect different
steps of a long-running process).

  The problem is that the nodes added after the construction
of the tree are not shown.  I guess I have to tell the tree
in some way that the tree model has changed, but I don't
know how.

  Below is a full simple sample that reproduce the same
issue I have, I think:

import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.WindowConstants;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

public class TreeAddNodes
{
    public static void main(String[] args)
    {
        // first part of the model
        DefaultMutableTreeNode root =
            new DefaultMutableTreeNode("node 1");
        root.add(new DefaultMutableTreeNode("node 2"));
        root.add(new DefaultMutableTreeNode("node 3"));

        // the model and the tree
        JTree tree = new JTree(new DefaultTreeModel(root));

        // second part of the model, NOT SHOWN!
        root.add(new DefaultMutableTreeNode("node 4"));
        root.add(new DefaultMutableTreeNode("node 5"));

        // GUI boilerplate
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(
                      WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(200, 200);
        frame.add(tree);
        frame.show();
    }
}

  Any comment greatly appraciated!

  Regards,

--drkm

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextNext in thread | Find similar | Unroll thread


Thread

JTree, updating model and "Florent Georges" <florent.georges@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000
  Re: JTree, updating model "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000

csiph-web