Is it possible to make a JTree without leaf? If it is possible then please tell me way.
I want to convert these highlighted leafs as the folder or parent.
If you want any thing else apart from it then please let me know.
Is it possible to make a JTree without leaf? If it is possible then please tell me way.
I want to convert these highlighted leafs as the folder or parent.
If you want any thing else apart from it then please let me know.
As shown in this FileTreeModel
, isLeaf()
should return false
and getChildCount()
should return 0
for directories. The result is illustrated here; although not apparent, the test
directory is empty.
@Override
public boolean isLeaf(Object node) {
File f = (File) node;
return !f.isDirectory();
}
@Override
public int getChildCount(Object parent) {
File f = (File) parent;
if (!f.isDirectory()) {
return 0;
} else {
return f.list().length;
}
}
I think if you always return true from isLeaf in your TreeModel but return 0 from getChildCount for your leaf nodes you'll get what you want.