我们可以使用动态 JTree 在根节点下创建一个空目录吗?例如:
我很想创建一个这样的jtree
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if (ADD_COMMAND.equals(command)) {
//Add button clicked
System.out.println("BUTTON CLICKED ");
DefaultMutableTreeNode p3,p4;
p3=treePanel.addObject("New Node " + newNodeSuffix++);
treePanel.addObject(p3, "newDir",false);
}
}
public void populateTree(DynamicTree treePanel) {
String p1Name = new String("Parent 1");
String p2Name = new String("Parent 2");
String c1Name = new String("Child 1");
String c2Name = new String("Child 2");
DefaultMutableTreeNode p1, p2;
p1 = treePanel.addObject(null, p1Name);
p2 = treePanel.addObject(null, p2Name);
treePanel.addObject(p1, c1Name);
treePanel.addObject(p1, c2Name);
treePanel.addObject(p2, c1Name);
treePanel.addObject(p2, c2Name);
}
在按钮单击事件上,如果不这样做,我就无法创建目录 **DefaultMutableTreeNode p3,p4;
p3=treePanel.addObject("New Node " + newNodeSuffix++);
treePanel.addObject(p3, "newDir",false);**
结果我得到的目录包含一个文件
我想避免 newDir 只需要空目录请帮助我......
任何帮助都是可观的......
非常感谢。