How Can Rename the Node of tree Using Interface TreeModal

N

Neeraj

hi,
this is my code summary:-

class DirectoryTreeModel implements TreeModel
{


public void addTreeModelListener(TreeModelListener l)
{

}

public Object getChild(Object parent, int index)
{

Directory dir = (Directory)parent;
return dir.getChild(index);
}

public int getChildCount(Object parent)
{
Directory dir = (Directory)parent;
if (!dir.isExpanded())
{
return 0;
}

return dir.getChildCount();
}

public int getIndexOfChild(Object parent, Object child)
{
Directory dir = (Directory)parent;

if (!dir.isExpanded())
{
return -1;
}
return dir.getChildIndex((Directory)child);
}

public Object getRoot()
{
return root;
}

public boolean isLeaf(Object node)
{
Directory dir = (Directory)node;

return dir.isLeaf();
}

public void removeTreeModelListener(TreeModelListener l)
{
}

public void valueForPathChanged(TreePath path, Object newValue)
{
DefaultMutableTreeNode
node;
node =
(DefaultMutableTreeNode)(arg0.getTreePath().getLastPathComponent());

String s = file.getPath();
String parent = file.getParent();
File file = new File(s);
File newfile = new File(parent+File.separator+newValue);
file.renameTo(newfile);
tree.repaint();
}


}
this is class which implement TreeModel used in my tree.
When i run this program then java.lang.ClassCastException: is
generated on node = (Def...) line. so i cannot apply changed name on
that node.
i m stuck here how can i uses this node.
i cannot use any other model.
any one have some idea plz write me for that i m thankful to you.
bye
Happy Sankrantri and Pongal to all of you.
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top