This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread 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 Elasticsearch in Action this week in the Big Data 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

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
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.
wood burning stoves
subject: How to create a File Explorer using JTree