How to show empty directories in JTree ?
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 ?
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
FileSystemView fileSystemView = FileSystemView.getFileSystemView();
where myFile is the UserObject of the node, cast to File.
JFileChooser fileChooser = new JFileChooser();
Try one of those and post back if you get stuck anywhere.