• Post Reply Bookmark Topic Watch Topic
  • New Topic

How i can get Folder Explorer

 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

does java has Folder Explorer like windows one (GUI)?
what is api name?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know file chooser

i am looking for some thing like folder tree
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can customize JFileChooser to show and allow selection of only directories/folders. Check out these JDC Tech Tips on customizing JFileChooser. You can setFileSelectionMode to JFileChooser.DIRECTORIES_ONLY - which allows the user to only select directories, and not files. To not show files at all, you will also need to create a FileFilter that filters out all files and shows all directories and pass it to setFileFilter.
 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
listing dirctory as a tree is the target and filechooser does not give this target
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create your own implementation of javax.swing.tree.TreeModel that deals with Files. For instance, "public int getChildCount(Object parent)" would cast parent to a File, calls listFiles() and returns the length of this array (or 0 if the array is null).

Just one hint: if you go this way, cache the arrays. If not, and you again call listFiles() in "public Object getChild(Object parent, int index)", then you will call listFiles() for each and every node in the tree. I did it this way before, and it took minutes to show a folder with 1000+ files.


You can also use File.listFiles(FileFilter) to limit the files you get as a return value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!