JTree node not displayed

Hi,

I am trying to create a JTree node and for some reason, the subnodes of my main Trilili node are not displayed when I use the following code:

// Initializing top node

DefaultMutableTreeNode Trilili = new DefaultMutableTreeNode("Trilili",true);

TreeModel OurStuff = new DefaultTreeModel(Trilili,true);

TheTree.setModel(OurStuff);

// Initializing children node

DefaultMutableTreeNode Tralala = new DefaultMutableTreeNode("Tralala",true);

Trilili.add(Tralala);

DefaultMutableTreeNode Trololo = new DefaultMutableTreeNode("Trololo",true);

Trilili.add(Trololo);

DefaultMutableTreeNode SubNode = new DefaultMutableTreeNode("SubNode",true);

Tralala.add(SubNode);

Yet, if I move the

TreeModel OurStuff = new DefaultTreeModel(Trilili,true);

TheTree.setModel(OurStuff);

lines at the end of my code, the nodes are being displayed at all (I don't mean unfolded). Does it mean I have to recreate a TreeModel each time I modify the structure of my JTree?

Please don't send me to How to use tree Tutorial, I have already read it and I could not find the answer to my question. Thanks.

[1186 byte] By [Jrma] at [2007-11-27 11:05:39]
# 1

Sorry, typo:

"lines at the end of my code, the nodes are being displayed at all (I don't mean unfolded). Does it mean I have to recreate a TreeModel each time I modify the structure of my JTree?"

should read

"lines at the end of my code, the nodes are being displayed. Does it mean I have to recreate a TreeModel each time I modify the structure of my JTree?"

Jrma at 2007-7-29 13:10:07 > top of Java-index,Java Essentials,Java Programming...
# 2

Ok, found the solution:

// Initializing top node

DefaultMutableTreeNode Trilili = new DefaultMutableTreeNode("Trilili",true);

DefaultTreeModel OurStuff = new DefaultTreeModel(Trilili,true);

TheTree.setModel(OurStuff);

// Initializing children node

DefaultMutableTreeNode Tralala = new DefaultMutableTreeNode("Tralala",true);

OurStuff.insertNodeInto(Tralala,Trilili,0);

DefaultMutableTreeNode Trololo = new DefaultMutableTreeNode("Trololo",true);

OurStuff.insertNodeInto(Trololo,Trilili,1);

DefaultMutableTreeNode SubNode = new DefaultMutableTreeNode("SubNode",true);

OurStuff.insertNodeInto(SubNode,Tralala,0);

Sorry if I woke up anyone (joke) ;-) !!!

Jrma at 2007-7-29 13:10:07 > top of Java-index,Java Essentials,Java Programming...