我在 Web 应用程序中使用 Wicket 的 Tree 组件。但是空文件夹以文件方式显示。像这样:
Bellow 是我使用 DefaultTreeModel 和 Tree 的地方:
PDMinterface pdmI = new PDMinterface();
DefaultMutabletreeNode rootTreeNode = pdmI.getDocTree(); //文档树根结点,由PDM接口提供
DefaultTreeModel treeModel = new DefaultTreeModel(rootTreeNode);
treeModel.setAsksAllowsChildren(true);
我确定 folder5 设置为允许孩子:
public DefaultMutableTreeNode getDocTree(){
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
root.setAllowsChildren(true);
FolderNode rootFolder = new FolderNode(0, "root", "Jiajun", true);
root.setUserObject(rootFolder);
for(int i=0; i < 5; i++){
DefaultMutableTreeNode newnode = new DefaultMutableTreeNode();
newnode.setAllowsChildren(true);
FolderNode newFolder = new FolderNode(i+1, "Folder" + Integer.toString(i+1), "Jiajun", false);
newnode.setUserObject(newFolder);
root.add(newnode);
if(i < 4){
for(int j=0; j < 5; j++){
DefaultMutableTreeNode newdocNode = new DefaultMutableTreeNode();
newdocNode.setAllowsChildren(false);
DocNode newDoc = new DocNode(10*(i+1) + j, "Document" + Integer.toString(10*(i+1)+j), "Jiajun");
newdocNode.setUserObject(newDoc);
newnode.add(newdocNode);
}
}
}