🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #790

JTree node update problem

#790
From: 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
Technical Details
Message-ID: <40dc5656$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,236ae22817be31e1,start
X-Google-Attributes: gid111d45,public
From: "George" <geo_54321@yahoo.com>
Newsgroups: borland.public.jbuilder.java.swing
Subject: JTree node update problem
Date: Fri, 25 Jun 2004 12:45:53 -0400
Lines: 52
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 63.119.115.129
Message-ID: <40dc5656$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1088181846 63.119.115.129 (25 Jun 2004 09:44:06 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail