DefaultMutableTreeNode myComputer = new DefaultMutableTreeNode("My Computer");
DefaultMutableTreeNode c = new DefaultMutableTreeNode("Local Disk(C:)");
DefaultMutableTreeNode vinod = new DefaultMutableTreeNode("Vinod");
DefaultMutableTreeNode swing = new DefaultMutableTreeNode("Swing");
DefaultMutableTreeNode tr = new DefaultMutableTreeNode("Tree");
DefaultMutableTreeNode a = new DefaultMutableTreeNode("3½ Floppy(A:)");
DefaultMutableTreeNode e = new DefaultMutableTreeNode("New Volume(E:)");
c.add(vinod);
vinod.add(swing);
swing.add(tr);
myComputer.add(c);
myComputer.add(a);
myComputer.add(e);
JTree tree = new JTree(myComputer);
JScrollPane scrollPane = new JScrollPane(tree);
jPanel1.add(scrollPane);
tree.setVisible(true);
我从网上获得了新的树示例,但是当我尝试显示它时,它没有出现!我不知道为什么。有任何想法吗?谢谢!