【发布时间】:2013-11-27 12:08:51
【问题描述】:
我使用默认的 NetBeans 编辑创建了一个表单,并在其上放置了 jTree。
然后它以某种方式在其中创建了一堆元素,例如“颜色”、“运动”、“食物”。但它不在创建代码中。它来自哪里以及如何编辑它...
即使我这样做 jTree1.removeAll(); 一切仍然存在......而且我的代码中没有用于向 jTree 添加新项目的代码。
private void test(java.awt.event.MouseEvent evt) {
//trying to remove all, but it does not remove anything
jTree1.removeAll();
//it does print it in debug meaning that this function is called
System.out.println("qwe");
//create the root node
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
//create the child nodes
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1");
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2");
//add the child nodes to the root node
root.add(child1);
root.add(child2);
//now how do I add it to the tree?
//???
}
我需要能够在运行时编辑jTree 内容。
【问题讨论】:
-
如何创建您的
JTree?你想做什么,不清楚。 -
我在 NetBeans 中使用表单构建器,我只是将它放在这个可视化编辑器中的表单上。除此之外,我什么也没做。
标签: java swing jtree removeall defaulttreemodel