• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree Load Directory  RSS feed

 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I would like to ask for some advices about how to load X directory to JTree.

For example C:/

Thanks in advice.
 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far? Do you already know how to read the files and sub folders in a folder?

After that you have a few options:
1) use DefaultTreeModel and DefaultMutableTreeNode. However, this requires you to put the entire drive into memory.
2) use a custom TreeModel. Do a search in this forum, as there have been similar threads about this.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best approach, I found, when learning a Swing component, was to start with Sun's tutorial (presumably now Oracle's tutorial) about the component. I would take the code from the tutorial and start modifying it until the final result was code for my requirements.

Last time I checked, there was a link from the JTree API documentation to the tutorial. Hopefully that hasn't been broken by the massive change in URLs resulting from the Oracle take-over.
 
Rob Spoor
Sheriff
Posts: 21050
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's still working. I like the lazy loading example there; that's something you really want with full file system trees. Directories are non-leaf nodes, and only when you expand it will you load its children.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!