我用默认的 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
在运行时编辑内容。