Solved

How to create directory tree in java?

Posted on 2007-04-05
4
3,811 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now