This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Using a tree for a file chooser? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using a tree for a file chooser?" Watch "Using a tree for a file chooser?" New topic
Author

Using a tree for a file chooser?

Phil Chuang
Ranch Hand

Joined: Feb 15, 2003
Posts: 251
How would I go about making a JTree component that I can use as a filechooser? EG, something that shows the directories as a tree structure, and being able to tell what node is currently selected.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

There's already a JFileChooser component to do that... but if you really wanted to do it yourself you could always just modify DefaultTreeModel to use the listRoots() method of the File class and build a subclass of DefaultMutableTreeNode that wraps a File reference. I would also only read one level of the directory at a time. You could do this by using a TreeExpansionListner and use the listFiles() method to create the children of the directory that's expanding.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
Don't get me started about those stupid light bulbs.
 
subject: Using a tree for a file chooser?
 
Similar Threads
WA #1.....word association
instanceOf??
WA#2 word association
WA #2 ..... word association
Tad Tree