• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Swing components-JTree and JFileChooser

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi..i was refered by a teacher of mine to this site..hope i can learn many things here..=)
i'm currently working on a project right now that aims to display the files and folders in a computer,one that works like a computer explorer/my computer function for windows users.i would like to use the JTree component in Swing to be able to display the files and folders of a computer so that it can be collapsed or expanded and its path can be displayed.
i thought at first of using the JFileChooser for this function.But since JFileChooser is a dialog box,i would like to "put a JFileChooser" in a JTree to be able to dynamically browse through a computer's contents and display it as a tree.
is there a class in java,besides JFileChooser,that can support this function?the one that can dynamically browse through a computer's contents?and one that can be displayed in a JTree/parent-children(folders-files) manner?
we are limited to use swing components only..
hope i can get some useful feedbacks..tnx..=)
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch, maxxinne!
Please don't post the same question in multiple forums, 'round these parts. It just makes it difficult to follow a conversation.
Moving this to the Swing / JFC / AWT forum...
 
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JFileChooser and JTree have entirely different purposes so you will have to do some work to get them to play together.
Looking at the workflow, the user will first use your JFileChooser to select a starting directory. You will then need to provide your JTree with an implementation of the TreeModel interface that can represent that directory and the files and directories contained within it as a tree. If you look at the Javadoc for JTree, TreeModel and DefaultTreeModel, there is a link to the Java tutorial on using trees. This is a good place to start. Have fun.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swing 2nd ed by Robinson & Vorobiev has an example of what you want.
 
I do some of my very best work in water. Like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic