This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes How to create a File Explorer using JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to create a File Explorer using JTree" Watch "How to create a File Explorer using JTree" New topic
Author

How to create a File Explorer using JTree

satya sahu
Ranch Hand

Joined: Mar 26, 2003
Posts: 97
Hi All,
How can i create a File Explorer using JTree in Swing so there is a tree representation for the localdisks? Left side showing the tree and right side showing the files of the selected folder in the tree. Expected behaviour is replication of winodws explorer behaviour.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
You could make a JTree for the left and a JTextArea for the right component, both in
JScrollPanes.
A JFileChooser allows you to navigate the file system and select files and directories. If a
directory is selected you can show its files in your tree. Use methods of the File class api
to collect the files. You could make up a small data store class to store the URL for each
file and return the file name in its toString method (which will be called by the treeNode
for display). Use this class as a wrapper for each file and use it as the userObject in each
DefaultMutableTreeNode for the tree.

When the user selects a node you can retrieve the wrapper from the node and get the file URL
which you then use to read the file into the textArea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a File Explorer using JTree