Solved

How to create directory tree in java?

Posted on 2007-04-05
4
3,820 Views
Last Modified: 2013-12-22
Anyone know how to create a directory tree using swing in Java?This tree is used for scaning all computer hard drive and directories inside each drive.
0
Comment
Question by:khoama
  • 2
4 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18860742
You can use a JFileChooser to select files in any directory if that is what you want.

http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html

Otherwise you ca create a JTree to represent your existing folder structure.

http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
0
 
LVL 2

Author Comment

by:khoama
ID: 18862730
I known all your solutions already.What I need is using java swing JTree to implement a directory tree.I have some examples but they are difficult to understand and implement.Is there any easier way?
0
 
LVL 1

Accepted Solution

by:
alban4 earned 500 total points
ID: 18865661
Try using the class javax.swing.filechooser.FileSystemView to build you JTree:
- getRoots() provides an array of file roots
- getFiles() returns all children of a given node (you will need to filter out non directories)
- getSystemIcon() returns the icon to use for a given node
0
 
LVL 2

Author Comment

by:khoama
ID: 18868309
thanks for the solution, I will try it.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question