TreeModelListener

From: csdev (csdev1978_at_yahoo.com)
Date: 05/28/04


Date: 28 May 2004 13:41:33 -0700

Hi All,

I have a JTree which is built using a customized Tree Model.
I query the data base to find new records by listening to tree will
expand.
Now these new records are added to the root/parent, but the Jtree is
not being updated.

I think I am not handling the listeners correctly. I have a
TreeModelListener added to the model. But none of the methods are
being called...do I need to fire the event manually? If yes, could
someone please provide a example.

DataModel model = new DataModel(root);
model.addTreeModelListener (new MyTreeModelListener());

    class MyTreeModelListener implements TreeModelListener{
     
       MyTreeModelListener(){
         
      }
   
       public void treeNodesChanged(TreeModelEvent e){
         System.out.println("treeNodesChanged");
      }
   
       public void treeNodesInserted(TreeModelEvent e){
         System.out.println("treeNodesInserted");
      }
   
       public void treeNodesRemoved(TreeModelEvent e){
         System.out.println("treeNodesRemoved");
      }
   
       public void treeStructureChanged(TreeModelEvent e){
         System.out.println("treeStructureChanged");
      }
   
   }

----------DataModel--------
private Vector treeModelListeners = new Vector();
<<<snip>>>>
 public void addTreeModelListener(TreeModelListener a) {
     
         treeModelListeners.addElement(a);
      }

public void removeTreeModelListener(TreeModelListener l) {
         treeModelListeners.removeElement(l);
      }

<<<snip>>>>

Thanks,
Cathy.