Narayanan Kaleeswaram wrote:
> Hello,
> What I will do for removing and loading another node in the same
> row to the JTree.Adding node to tree is as follows(in ActivateEvent of
> the InternalFrame).
> -------------
> dmtnFun=new DefaultMutableTreeNode(filename);//dmtnFun,
> DefaultMutableTreeNode
> //filename is String
> funTree=new JTree(dmtnFun);//JTree object
> panFun.add(funTree); panFun is a JLabel
> for(int i=0;i<10;1++)
> dmtnFun.add(new DefaultMutableTreeNode(fun[i])); //fun is a String
> array
> ((DefaultTreeModel)funTree.getModel()).reload(dmtn Fun);
> would like to remove this perticlar node(dmtnFun) from the tree in
> DeactivateEvent of the InternalFrame and add new node(dmtnFun) with
> the above code.
Provide real code, not this random collection of lines.
What I can guess from his mess is:
You are not changing the data via the TreeModel, but you somehow
mess with the JTree and the individual nodes. Don't do this.
Also, do not use reload(). The TreeModel methods for inserting and
removing nodes are supposed to fire the necessary events to the
JTree. If you use a DefaultTreeModel, this firing is already
implemented. If you have your own implementaion of TreeModel, you
are supposed to implement this handling.
Get a good book about Swing, or at least read the Sun GUI tutorial,
and the Swing architecture article in Sun's TCS article collection.
/Thomas
|