Board index » jbuilder » JTree node update problem

JTree node update problem


2004-06-26 12:45:53 AM
jbuilder17
I am having trouble understanding how to update the display of JTree nodes.
My tree displays the file system hierarchy of directories. The user object
of each node is a File object representing the directory. I would like the
user to be able to rename a selected directory. I have a context menu on
the tree with a Rename action whose actionPerformed method has a
renameFile() method as below:
String newName = JOptionPane.showInputDialog(frameWindow, "Enter new
name for directory");
File f = new File(file.getParent() +"\\" + newName);
if (f.exists()) {
throw new Exception( "Directory already exists: \n" +
f.getAbsolutePath());
}
if (!file.renameTo(f))
throw new Exception("Failed to rename file: \n" +
file.getAbsolutePath());
treeModel = (FileSystemTreeModel) fsTree.getModel();
treeModel valueForPathChanged(selectedPath, f);
This renames the file (I can verify this by refreshing the tree) but doesn't
update the tree's display. The tree continues to have the old directory
name until I perform a reload of the model. I would like to see the
directory name changed without having to reload() the model since this
collapses all expanded nodes.
Any help will be appreciated.
George
 
 

Re:JTree node update problem

George wrote:
Quote
I am having trouble understanding how to update the display of JTree
nodes.



My tree displays the file system hierarchy of directories. The user
object
of each node is a File object representing the directory. I would like
the
user to be able to rename a selected directory. I have a context menu on
the tree with a Rename action whose actionPerformed method has a
renameFile() method as below:

Have you tried updating the UI at the parent level?