Related to Jtree with 3000 nodes... Problem

Hi,

I am unable to reply to the archive of "Jtree with 3000 nodes" problem..Hence posting it as a new topic.

I have a Jtree and i am adding nodes dyamically to the tree on clicking each node. For the handle to show up I was adding dummy nodes earlier, and on clicking on the node handle I remove the dummy node and add the original children. But now I am following what Mr. Vattivs advised in the "Jtree with 3000 nodes" . I am overriding the treenode class to return false for isleaf().

Now the handle is showing up, and on clicking on the handle the children are getting added to the node.

But the children are not visible. I tried tree.revalidate, repaint...but my children are not showing up.

Please help me to display them.

Thankx.

[780 byte] By [athipatlaa] at [2007-10-2 3:17:27]
# 1
I would expect you to fire a TreeModelEvent to thevoid treeStructureChanged(TreeModelEvent e)method of all the model listeners.
sabre150a at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 2
Hi Sabre,Currently I am firing a Tree Expansion event, if i fire a Tree model event will that be precise ?I'll try that..thankx...
athipatlaa at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 3

> Hi Sabre,

> Currently I am firing a Tree Expansion event, if i

> fire a Tree model event will that be precise ?

> I'll try that..

> thankx...

When one updates the JTree model one signals this by firing an event to all the registered listeners. Since the JTree is registered as a listener when the model is attached it knows that it has to update the view. The notification method called in conjunction with the event content tells the listeners what has changed.

You need to get the path to the node that has changed. You can either create the path as an array of objects or directly as a TreePath object.

I know this works because I do it all the time. I never have to use revalidate() or any of the view methods. The view methods have no part to play in dealing with a change in the model.

sabre150a at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 4

I add children to the node only on clicking on the node handle. i.e. as a node expansionevent I add child nodes.

I also add a void treestructurechanged (treemodelevent ) as u said and get the treepath inside.

But,

It does not even come inside the treestructurechanged or its other related events like treenodesinserted, treenodesremoved or treenodeschanged. Even after I add the children to the node (during the node expansion event ).

What shuld i do for the listener to get called ? After that what shud i do with the path for my added node to get visible ?

Thankx

athipatlaa at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 5
Hi Sabre,Can u add some pseudo code to help me understand betterThannxRaj
athipatlaa at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 6

> Hi Sabre,

> Can u add some pseudo code to help me understand

> better

> Thannx

> Raj

Not really! If in your model you have a node with (say) 5 children and you add (say) two more children to the model then you need to create a TreeModelEvent that indicates what has changed. The relevant constuctor will probably be

public TreeModelEvent(Object source,

Object[] path,

int[] childIndices,

Object[] children)

where the

'source' is your tree model,

'path' is an array of nodes linking the parent of the children being added to the root

'childIndices' is an array indicating were you have inserted the nodes. If you have just appended two child nodes then this will be an array of length 2 containing the integers 5 and 6 which says you have added nodes with indexex 5 and 6.

'children' will be null since the JTree wil get the values from the model.

Then, for each TreeModelListener added to the model, you call the method

void treeNodesInserted(TreeModelEvent e)

supplying the event you have just created.

If you are using DefaultTreeModel (which I almost never do) then there are a set of convenience methods to assist in all of this.

sabre150a at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 7
Yes...I use default tree model only...raj
athipatlaa at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 8

I tried that...I tried adding the Tree Model Event as both treenodesinserted , as well as treenodeschanged, but the children are not still not diaplaying...

But sabre....Before that I need to clarify one thing...Is the nodes inserted only for cases where we already have nodes or if we freshly add nodes also will it work ?

B'cos I dont have any children to the node...After clicking on the node only I add them..

Thankx

Raj

athipatlaa at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 9

> I tried that...I tried adding the Tree Model Event as

> both treenodesinserted , as well as treenodeschanged,

> but the children are not still not diaplaying...

You have obviously not coded it correctly and without seeing your code I have no way of diagnosing what is wrong.

> But sabre....Before that I need to clarify one

> thing...Is the nodes inserted only for cases where we

> already have nodes or if we freshly add nodes also

> will it work ?

Of course! In insert at the end of the list is an add!

> B'cos I dont have any children to the node...After

> clicking on the node only I add them..

I do that without problem.

> Thankx

> Raj

I see three likely possibilities -

1) You have not added the nodes to the model BEFORE you fire the event.

2) The event parameters are wrong

3) You are not firing the event

Without your code being published I can help no more!

sabre150a at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...
# 10
Hi Sabre...I was adding the child to the parent using the method parent.add(child) But now, I add the node using treemodel.insertnode and then i reload the treemodel by giving the node...Now it is working fine...Thankx for your valuable help..RegardsRaj
athipatlaa at 2007-7-15 21:44:48 > top of Java-index,Desktop,Core GUI APIs...