tags:

views:

66

answers:

1

I'm using a custom TreeModel for a JTree. I have an issue when I insert a new node into my TreeModel, and then call treeNodesInserted(TreeModelEvent) on all my TreeModelListeners.

I think the issue has to do with the fact that JTree.TreeModelHandler has no implementation for treeNodesInserted(e), only treeStructureChanged(e)

obviously for me it would be a lot better to be able to insert, instead of a full tree structure changed.

Is there a workaround? (I can't use DefaultTreeModel)

+1  A: 

Some more details would help. But I have done a similar thing with no issues. In my case I've got MyTreeModel implements TreeModel, and a fireTreeInserts function is part of it.

The function looks something like this (cleaned application specific code):

   public void fireTreeInsert(TreePath path, Object child) {
      Object[] children = {child};
      int index = this.getIndexOfChild(path.getLastPathComponent(), child);
      int[] indicies = {index};
      TreeModelEvent e = new TreeModelEvent(this, path, indicies, children);
      EventListener[] listeners = mTreeModel.getListeners(TreeModelListener.class);
      for (int ii = 0; ii < listeners.length; ii++) {
         ((TreeModelListener)listeners[ii]).treeNodesInserted(e);
      }
   }
drye