Hi,
I use JTree in combination with my own TreeModel. Whenever a new node is to
be inserted I call all listeners to tell them that the structure of the tree
has changed but nothing happens! The new nodes don't appear. What am I
missing? Removing nodes works perfectly...
I figured out that JTree registers itself as a listener but it doesn't seem
to react on changes. I changed the call from "treeStructureChanged" to
"treNodesInserted" - no success either and a look at the source of JTree
says me that the implementation of this method is empty.
Here's piece of the code that informs the listeners:
public void insertItemAdapter(TreeControl.Item abstractItem)
{
// I wrap my nodes into special adapters.
SwingTreeControlItemAdapter newItem =
new SwingTreeControlItemAdapter(abstractItem);
// Helps me to find the adapter.
itemMap.put(abstractItem, newItem);
// Create a treepath down from the new item up to the root.
TreePath pathToRoot = getPathToRoot(newItem);
// Iteratr all listeners.
Iterator listenerIterator = listeners.iterator();
TreeModelListener actListener;
while(listenerIterator.hasNext())
{
actListener = (TreeModelListener)listenerIterator.next();
actListener.treeStructureChanged(new TreeModelEvent(this,
pathToRoot));
}
}
Any ideas?
Thanks.
René
Rene Ruppert - 23 May 2005 15:19 GMT
btw: I forgot to mention that it works, when the parent of the new node is
not expanded yet!
Or the other way round: inserting a new node only works, when its' parent is
collapsed...
Rene Ruppert - 23 May 2005 15:51 GMT
Okay, found it...using
actListener.treeNodesInserted(new TreeModelEvent(this, pathToRoot,
childIndices, children));
to create the event shows the new node...
René