wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
Similar Threads
JTree and leaf nodes
JTree
JTree
JTree
JTree