无法使用 Java netbeans 加载节点 jTree
Cannot load the nodes jTree using Java netbeans
这是我第一次使用 java 使用 jtree。但是当我尝试加载它时我无法加载它显示为 blank.i 不知道如何加载 it.what 我试过到目前为止我附上了 below.please 给我解决方案谢谢。 JTree 名称是 jTree1
DefaultTreeModel root1;
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
public void Load()
{
DefaultMutableTreeNode vegetableNode = new DefaultMutableTreeNode("Vegetables");
vegetableNode.add(new DefaultMutableTreeNode("Capsicum"));
vegetableNode.add(new DefaultMutableTreeNode("Carrot"));
vegetableNode.add(new DefaultMutableTreeNode("Tomato"));
vegetableNode.add(new DefaultMutableTreeNode("Potato"));
DefaultMutableTreeNode fruitNode = new DefaultMutableTreeNode("Fruits");
fruitNode.add(new DefaultMutableTreeNode("Banana"));
fruitNode.add(new DefaultMutableTreeNode("Mango"));
fruitNode.add(new DefaultMutableTreeNode("Apple"));
fruitNode.add(new DefaultMutableTreeNode("Grapes"));
fruitNode.add(new DefaultMutableTreeNode("Orange"));
root.add(vegetableNode);
root.add(fruitNode);
root1 = (DefaultTreeModel)jTree1.getModel();
}
您需要将树添加到根,然后将树添加到 JTree
:
root1 = (DefaultTreeModel)jTree1.getModel();
收件人:
root1.setRoot(root);
jTree1.setModel(root1);
这是我第一次使用 java 使用 jtree。但是当我尝试加载它时我无法加载它显示为 blank.i 不知道如何加载 it.what 我试过到目前为止我附上了 below.please 给我解决方案谢谢。 JTree 名称是 jTree1
DefaultTreeModel root1;
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
public void Load()
{
DefaultMutableTreeNode vegetableNode = new DefaultMutableTreeNode("Vegetables");
vegetableNode.add(new DefaultMutableTreeNode("Capsicum"));
vegetableNode.add(new DefaultMutableTreeNode("Carrot"));
vegetableNode.add(new DefaultMutableTreeNode("Tomato"));
vegetableNode.add(new DefaultMutableTreeNode("Potato"));
DefaultMutableTreeNode fruitNode = new DefaultMutableTreeNode("Fruits");
fruitNode.add(new DefaultMutableTreeNode("Banana"));
fruitNode.add(new DefaultMutableTreeNode("Mango"));
fruitNode.add(new DefaultMutableTreeNode("Apple"));
fruitNode.add(new DefaultMutableTreeNode("Grapes"));
fruitNode.add(new DefaultMutableTreeNode("Orange"));
root.add(vegetableNode);
root.add(fruitNode);
root1 = (DefaultTreeModel)jTree1.getModel();
}
您需要将树添加到根,然后将树添加到 JTree
:
root1 = (DefaultTreeModel)jTree1.getModel();
收件人:
root1.setRoot(root);
jTree1.setModel(root1);