the value is chnaged when editing stopped , you will get the new edited value.
Main Topics
Browse All Topicspublic void editingStopped(ChangeEvent
{
DefaultMutableTreeNode = (DefaultMutableTreeNode ) tree.getSelectionPath().ge
treeModel.nodeStructureCha
/********
How do I do the renaming bit here?????
The user was editing the node, changed the text and this event was fired - how do i get the new text??
************/
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi, ill just post all the code - it is just a Default cell editor, i didnt bother to over-ride anything. And ill post the tree node class too. The idea is when the user edits the node, the associated directory will be renamed. Thankyou.
/********* THE TREE EDITOR DECLARATION **************/
CellEditorListener cel = new CellEditorListener()
{
public void editingStopped(ChangeEvent
{
FileTreeNode node = (FileTreeNode) tree.getSelectionPath().ge
treeModel.nodeStructureCha
String s = e.toString();
// physically rename directory
//renameDirectory(node.get
}
public void editingCanceled(ChangeEven
{
}
};
DefaultTreeCellEditor editor = new DefaultTreeCellEditor(tree
editor.addCellEditorListen
tree.setCellEditor(editor)
tree.setEditable(true);
/*************** TREE NODE CLASS ************************/
public class FileTreeNode extends DefaultMutableTreeNode
{
/** FileTreeNode - File userObject, boolean allowsChildren */
public FileTreeNode(File userObject, boolean allowsChildren)
{
super(userObject, true);
}
/** FileTreeNode - File userObject, allows children (by default) */
public FileTreeNode(File userObject)
{
super(userObject, true);
}
/** FileTreeNode - NO userObject, allows children (by default) */
public FileTreeNode()
{
super();
}
/** Convenience method - set the userObject, only type java.io.File allowed */
public void setFile(File userObject)
{
this.setUserObject(userObj
}
/** Convenience method - get the userObject, generic type java.io.File allowed */
public File getFile()
{
return (File) this.getUserObject();
}
/** Over-ride super-class, only sets userObject if of type java.io.File */
public void setUserObject(Object userObject)
{
if (userObject instanceof File)
super.setUserObject(userOb
}
/** Returns the filename of the java.io.File userObject */
public String toString()
{
File temp = getFile();
if(temp != null)
return temp.getName();
else
return "";
}
}
Could you try (not sure at all):
CellEditorListener cel = new CellEditorListener() {
public void editingStopped(ChangeEvent
{
FileTreeNode node = (FileTreeNode) tree.getSelectionPath().ge
treeModel.nodeStructureCha
DefaultTreeCellEditor editor = (DefaultTreeCellEditor)you
String newName = (String) editor.getCellEditorValue(
System.out.println("new name= " + newName);
// Do the renaming
// ...
}
If I may ask 1 more question?
I solved the problem with:
CellEditorListener cel = new CellEditorListener()
{
public void editingStopped(ChangeEvent
{
// fire change in model
TreePath path = tree.getSelectionPath();
FileTreeNode node = (FileTreeNode) path.getLastPathComponent(
treeModel.nodeStructureCha
// apply change to user object (File)
DefaultTreeCellEditor editor = (DefaultTreeCellEditor)tre
String newName = (String) editor.getCellEditorValue(
if(newName != null)
{
File newFile = new File(node.getFile().getPar
if (!newFile.exists())
{ // physically rename directory and update user object
if (node.getFile().renameTo(n
node.setFile(newFile);
}
else
{
I18N.mkDialog(bundle, null, "error.fileExists", "error.user.dialogTitle", JOptionPane.ERROR_MESSAGE)
// re-start editing
tree.startEditingAtPath(pa
/************* I restart cell editing here like eg, Windows explorer would. But am I able to select all the text of this node?? when tree editing starts nothing is selected and the cursor is in last position - i would just like all the text selected??
So I should use a TreeModelListener. I would still like to use a DefaultTreeModel?
So I inherit the methods:
public void treeNodesChanged(TreeModel
{
}
public void treeNodesInserted(TreeMode
{
}
public void treeNodesRemoved(TreeModel
{
}
public void treeStructureChanged(TreeM
{
}
How now would I achieve the same as in the code I posted above?
Business Accounts
Answer for Membership
by: zzynxPosted on 2004-11-02 at 06:21:15ID: 12472788
>>how do i get the new text??
ing()
Well, since you have the TreeNode it can't be that difficult.
What about
node.toString()
or
node.getUserObject().toStr
?