wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Listing files from a folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Listing files from a folder" Watch "Listing files from a folder" New topic
Author

Listing files from a folder

Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2579

This is what I am trying to do -
I want to have a drop-down box at the top from which user can select the desired folder/directory, and the table below will display all the files with their attributes, size type etc. I have managed to finish the Table part iof this succesfully. My question is - "How can I have a drop-down list of folders from which user can select at the top?" Is there any component available in swing which can be customized to display this, I couldn't do it with FileChooser. The list must be displayed all the time in the application, is this feasible using FileChooser?
TIA,
- Manish
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2579

Let me try to elaborate this -
In short, I want to have the listbox which is situated at top in the JFileChooser dialog in my application. How can I do this?
TIA,
- Manish
netharam ram
Ranch Hand

Joined: Aug 09, 2001
Posts: 202
The method File.listRoots() diplays the drives present in the system.U can then create a File of the selected item in the Listbox & use new_file.listFiles() to display the files & folders in that drive & if it is a folder then display it else leave it.
Happy middling with java. :
Netharam.
[ February 06, 2002: Message edited by: netharam ram ]
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2579

Thanks
Finally, I DID manage to do it the way I wanted, just like JFileChooser dialog. I knew abt the File.listRoots() method, puting folder hierarchically was a problem there. This is what I have done -
1) Made my own ListCellRenderer, depending upon the directoty depth, it decides the location at which the icon is drawn, and displays the file/dir name.
2) If it's a dir, it draws dir icon, if root, root icon and if it's a file a file icon.
3) The directory and its parents are listed by doing FIle.getParent() in a loop until it finds the corresponding root.
Thanks anyway,
- Manish
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Listing files from a folder