🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages Started by George Fri, 25 Jun 2004 16:45
JTree node update problem
#790
Author: George
Date: Fri, 25 Jun 2004 16:45
50 lines
2144 bytes
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
#799
Author: Paul Nichols (TeamB)
Date: Wed, 30 Jun 2004 13:18
16 lines
1370 bytes
George wrote:

> 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?
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads