Solved

How to create directory tree in java?

Posted on 2007-04-05
4
3,833 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 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