removing node from the JTree

  • Thread starter Narayanan Kaleeswaram
  • Start date
N

Narayanan Kaleeswaram

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)); //fun is a String
array
((DefaultTreeModel)funTree.getModel()).reload(dmtnFun);
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.
 
T

Thomas Weidenfeller

Narayanan said:
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)); //fun is a String
array
((DefaultTreeModel)funTree.getModel()).reload(dmtnFun);
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

change icon in jtree 0
Programmatically removing nodes from a JTree 2
JTree model update problem 3
Jtree renderers 0
JTree question 1
JTree oddity... 5
JTable within JTree 1
Extra Row in JTree 6

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top