DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    635

    Listing a directory

    How could I display a list of a directory? I need something like the directory tree in windows file explorer. The only method I can think of is reading all the files on a drive and creating a JList with it. But I was hoping that there might be a class that already does this.

  2. #2
    Join Date
    Feb 2004
    Posts
    808
    something like this pseudocode:

    Code:
    public void populateTree(File root, JTreeNode toPopulate)
    
    File[] dirEntries = f.listFiles();
    
    for(int i = 0; i< dirEntries.length; i++){
      if(dirEntries[i].isDirectory())
        toPopulate.add(dirEntries[i]);
    }
    make a tree with just "c:\" in it

    upon click, call that method and pass in a file pointing to the tree node, and the tree node itself, and youll get on-the-fly population of the tree

    -

    alternatively you can do ahead-of-fly population, and populate node with children before it is clicked on.
    note that expanding C:\ would hence require that you populate ALL of c:\ child nodes with THEIR children.. slow

    explorer does on the fly popuatlion: it draws a + next to every folder and if it finds out the node has no children it removes it. good idea.
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

  3. #3
    Join Date
    Mar 2004
    Posts
    635
    Unless I add files to the node, it displays a file icon with no + sign. How could I make it display the node as a folder without adding its inner contents to it?

    I did try reading in the whole C-drive. As you said, it was very slow. In fact, I didn't even let it finish as it was taking too long.

  4. #4
    Join Date
    Feb 2004
    Posts
    808
    subclass the tree and change the icon that it paints by default
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links