Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4593792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:44:07+00:00 2026-05-21T22:44:07+00:00

I have a ftp program that retrieve folder data each time expanded. It does

  • 0

I have a ftp program that retrieve folder data each time expanded. It does this by using a model like this:


    private void FilesTreeTreeExpanded(javax.swing.event.TreeExpansionEvent evt) {
String path = new String("");

 DefaultMutableTreeNode chosen = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();

 String[] pathArray = evt.getPath().toString().replaceAll("]", "").split(",");
 for (int i = 1 ; i < pathArray.length ; i++) path += "/"+ pathArray[i].trim();

// i were aded chosen.removeAllChildren(); without success
ftp.GoTo(path);

ArrayList listDir = null;
listDir = ftp.ListDir();

ArrayList listFiles = null;
listFiles = ftp.ListFiles();

DefaultMutableTreeNode child = null , dir = null , X = null;

//this will add files to tree
for (int i = 0; i < listFiles.size(); i++) {
child = new DefaultMutableTreeNode(listFiles.get(i));
if(listFiles.size() > 0)
model.insertNodeInto(child, chosen, 0);
}

//this will add dirs to list

for (int i = 0; i < listDir.size(); i++) {
X = new DirBranch("در حال دریافت اطلاعات ...").node();
dir = new DirBranch( (String) listDir.get(i)).node();
dir.add(X);
if(listDir.size() > 0)
model.insertNodeInto(dir, chosen, 0);
}

FilesTree.setModel(model); //this is my Swing JTree
}

the problem is every time i expand the JTree it duplicate list of files and folders. so i tried to use chosen.removeAllChildren(); @ the top of the code but it didnt remove anything. what should i do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:44:07+00:00Added an answer on May 21, 2026 at 10:44 pm

    Your model is correct, but JTree is operating on old information.

    The removeAllChildren() method removes the children, but it does not fire any events and the model.insertNodeInto() does fire insert events. So, JTree sees the nodes being added, but never sees the nodes being removed.

    After adding the new children, try calling model.reload(chosen) to invalidate the tree below chosen.

    Since you will be reloading the branch, you can also change model.insertNodeInto(dir, chosen,0) to chosen.insert(dir,0). That reduces the number of events posted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a system which is writing files to a folder using FTP. I
We have a ftp system setup to monitor/download from remote ftp servers that are
I have seen: http://www... ftp://blah.blah... file://blah.blah... unreal://blah.blah... mailto://blah.blah... What is that first section where
We have a C# application that connects to a FTP server, downloads some files,
I have an existing Perl script that uses the FTP object to send a
I have one console app that is doing some lengthy syncing to an ftp
I know this can be done and i have seen it done using some
I'm writing a program that uploads huge amounts of data and I need to
I have implemented a read/write stream to read a buffer, manipulate the data(like adding
I have a c# application that I use a custom FTP library for. Right

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.