I can't see dynamically added node in JTree.
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dmitry_Zakharov
Posted On:   Wednesday, April 10, 2002 10:24 PM

I create JTree and try to add new node to it. But I don't see new node. I try to set my CellRenderer, but it isn't ask fot component for new node. But I can ask parent tree node that the new child is added, count of children is increased. I can go from root node and print all tree nodes on console and I see that new nodes are appeared. But I don't see them on the screen !


Does anybody know the reason of invisibility of new added node ? You can be very helpful for me !


Thanks beforhand

Re: I can't see dynamically added node in JTree.

Posted By:   Sergey_Vtorov  
Posted On:   Wednesday, April 17, 2002 09:45 AM

If you are using DefaultTreeModel (default model used by JTree), then you should use model's insertNodeInto() method to add a new node.


JTree tree;
MutableTreeNode parent;
MutableTreeNode child;

...
// to append child node to the parent node
((DefaultTreeModel)tree.getModel()).
insertNodeInto(child, parent, parent.getChildCount());


Re: I can't see dynamically added node in JTree.

Posted By:   Paul_Connaughton  
Posted On:   Thursday, April 11, 2002 04:38 AM

How are you adding the node to the JTree?



If you add it directly to a DefaultMutableTreeNode like so:


((DefaultMutableTreeNode)myJTree().getModel().getRoot()).add( myChildNode );

then no events are generated and the JTree is not updated on the screen.


However if you make changes through the DefaultTreeModel like this:


((DefaultTreeModel)myJTree.getModel()).insertNodeInto( myChildNode, (DefaultMutableTreeNode)myJTree().getModel().getRoot(), 0 );

Then the events are triggered and the UI is updated.

Re: I can't see dynamically added node in JTree.

Posted By:   shautvas_t  
Posted On:   Thursday, April 11, 2002 12:53 AM

have u tried JTree.updateUI() ???

Re: I can't see dynamically added node in JTree.

Posted By:   eyal_lior  
Posted On:   Thursday, April 11, 2002 12:52 AM

You have to call

nodesWereInserted(parentNode, Childindexes[])



If I added just one node:


int[] indexOfNewNode = new int[1];

indexOfNewNode[0] = treeNode.getIndex(nextTreeNode);


_directoriesTree.nodesWereInserted(treeNode, indexOfNewNode);
About | Sitemap | Contact