Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How i can get Folder Explorer

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

does java has Folder Explorer like windows one (GUI)?
what is api name?
 
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out JFileChooser here
 
hassan ali
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know file chooser

i am looking for some thing like folder tree
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
listing dirctory as a tree is the target and filechooser does not give this target
 
Sheriff
Posts: 22574
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic