我使用默認的NetBeans edito創建了一個表單,並在其上放置了一個jTree
。 它以某種方式創造了一堆元素,如「顏色」,「運動」,「食物」。但它不在創建代碼中。它來自哪裏,我怎麼編輯它...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?你想做什麼,不清楚。 – alex2410
我在NetBeans中使用表單構建器,我只是將它放在此可視化編輯器中的表單上。除此之外,我沒有做任何事情。 – NewProger