Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileTreeModel Multiple Roots

Tags:

java

swing

jtree

I use this code here to create a file tree model. I want it to browse files. How can I add multiple roots? E.g. list C:/, D:/, E:/.

like image 370
Nick Doulgeridis Avatar asked Dec 28 '22 01:12

Nick Doulgeridis


1 Answers

A TreeModel can only have one root node, but you can use JTree.setRootVisible() to hide the root node when displaying the tree. Modify your model to have a virtual root node that contains each filesystem root (C:\, D:\, E:\, etc.), and call JTree.setRootVisible(false) on your JTree.

like image 160
Kevin K Avatar answered Jan 08 '23 03:01

Kevin K