Problem adding Child in AbstractTreeTableModel

Hello,

I have a AbstractTreeTableModel.

Root

|

Parent

|

Child 1

Adding of any number of parents is working fine. But When I try to add the second child, the child is not shown in the view. But I can see that the CHild 2,... gets inserted into the Model?

Can anyone help me please in resolving this issue?

I searched the forum and I was not able to find anything for AbstractTreeTableModel..

Thanks

Irfaan

[479 byte] By [Irfan_dcrtia] at [2007-11-27 11:54:49]
# 1

Hello All,

I did a fireTreeStructureChanged and it worked fine!

Thanks for reading :-)

Irfaan

Irfan_dcrtia at 2007-7-29 18:58:12 > top of Java-index,Desktop,Core GUI APIs...
# 2

Well, I doubt you are using an AbstractTreeTableModel since ABSTRACT means you can't create an instance of that class. You need to write another class that extends it.

So assuming you are using the DefaultTreModel, you add a node with code like the following:

DefaultTreeModel model = (DefaultTreeModel)tree.getModel();

DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();

root.add(new DefaultMutableTreeNode("another_child"));

model.reload(root);

camickra at 2007-7-29 18:58:12 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hi camickr,

Thanks for your reply.

I checked the reload method of DefaultTreeModel. It is actually calling fireTreeNodesChanged. Hence, I called fireTreeNodesChanged after adding a child. The tree was showing the new child then.

Regards

Irfaan

Irfan_dcrtia at 2007-7-29 18:58:12 > top of Java-index,Desktop,Core GUI APIs...
# 4

> Hence, I called fireTreeNodesChanged after adding a child.

Which is correct.

You should not be invoking fireTreeStructureChanged. There is a big difference.

camickra at 2007-7-29 18:58:12 > top of Java-index,Desktop,Core GUI APIs...