Tree Expansion

Hello,

In my program, I have created tree for the directory structure available on a particular location say C:\MyDirectories.

Its woking fine, but tree shows the node as EXPANDABLE i.e. [ + ] even there are no subdirectories/files inside that node.

i.e. If the node is empty, then tree should not show the '+' ( EXPANDABLE sign) behind that empty node.

Regards

[396 byte] By [nikhil_shravanea] at [2007-11-27 11:24:16]
# 1

Does getChildCount work correctly for your nodes?

CeciNEstPasUnProgrammeura at 2007-7-29 15:57:17 > top of Java-index,Java Essentials,Java Programming...
# 2

I am not using getChildCount.

this is the sample code I have written.

DefaultMutableTreeNode makeNewTree(File f, DefaultMutableTreeNode root)

{

DefaultMutableTreeNode root1 = new DefaultMutableTreeNode(f.getName());

File f1[] = f.listFiles();

for(int i = 0 ; i < f1.length ; i++ )

{

if(f1[i].isDirectory())

{

root1 = new DefaultMutableTreeNode(f1[i].getName());

makeNewTree(f1[i], root1);

root.add(root1);

}

}

return root;

}

Above is the recursive method which first creates the tree and then returns the node which is displayed.

If anything unclear, please ask.

Thanks and regards.

nikhil_shravanea at 2007-7-29 15:57:17 > top of Java-index,Java Essentials,Java Programming...
# 3

How can I remove the handle i.e [+ sign] behind the folder [node of the tree], if that folder doesn't have any sub folders. When I expand that node [which is empty] , Its [+ sign] gets removed.

Thanks and regards

nikhil_shravanea at 2007-7-29 15:57:17 > top of Java-index,Java Essentials,Java Programming...