How to show empty directories in JTree ?
Hello
I am trying to use JTree to show a directory tree on my filesystem.
The problem is that some of the directories on the file system are empty. JTree, in its default behavior, assumes that a node that does not have children is a leaf node and changes its icon accordingly.
I want "directory" node to show as directories and only "file" nodes to show as leaf nodes.
How do I change JTree's default behavior ?
Thanks
Guy
Re: How to show empty directories in JTree ?
I presume you are populating the JTree with File objects. If not, you need to do this first.
Use a custom renderer that sets the icon. You can use either
Code :
FileSystemView fileSystemView = FileSystemView.getFileSystemView();
setIcont(fileSystemView.getSystemIcon(myFile));
or
Code :
JFileChooser fileChooser = new JFileChooser();
setIcon(fileChooser.getIcon(myFile));
where myFile is the UserObject of the node, cast to File.
Try one of those and post back if you get stuck anywhere.
db