Hello
I am trying to use JTree to represent a file structure. It reads the files in a folder and put it in the tree. The Problem is if a folder is empty is not displayed correctly in the JTree (It gets displayed as a leaf).
Is there some way to force a node not be displayed as a leaf?
Here is some code:
Thanks in advance, any help will be appreciated.
I am trying to use JTree to represent a file structure. It reads the files in a folder and put it in the tree. The Problem is if a folder is empty is not displayed correctly in the JTree (It gets displayed as a leaf).
Is there some way to force a node not be displayed as a leaf?
Here is some code:
Code:
public void buildNodes(DefaultMutableTreeNode parentNode)
{
DefaultMutableTreeNode node = null;
DefaultMutableTreeNode mainNode = null;
String projRoot = m_parent.getFileRoot() + m_projID + "\\";
File dir;
String[] files;
/* Opportunity */
mainNode = new DefaultMutableTreeNode(new ModuleNode("Opportunity"));
dir = new File(projRoot + "Opportunity\\");
files = dir.list();
if (files == null) {
// Either dir does not exist or is not a directory
} else {
for (int i=0; i<files.length; i++) {
// Get filename of file or directory
node = new DefaultMutableTreeNode(new ModuleNode(files[i]));
mainNode.add(node);
}
}
parentNode.add(mainNode);
/* Initiation */
mainNode = new DefaultMutableTreeNode(new ModuleNode("Initiation"));
dir = new File(projRoot + "Initiation\\");
files = dir.list();
if (files == null) {
// Either dir does not exist or is not a directory
} else {
for (int i=0; i<files.length; i++) {
// Get filename of file or directory
node = new DefaultMutableTreeNode(new ModuleNode(files[i]));
mainNode.add(node);
}
}
parentNode.add(mainNode);
Thanks in advance, any help will be appreciated.