/*最简单的JTree示例*/
class MyTree extends JFrame{
public MyTree(String s){
super(s);
Container con = new getContentPane();
DefaultMutableTreeNode root = new DefaultMutableTreeNode("d:\\")
DefaultMutableTreeNode t1 = new DefultMutableTreeNode("BFZL");
DefaultMutableTreeNode t2 = new DefaultMutableTreeNode("JavaXX");
DefaultMutableTreeNode t1_1 = new DefaultMutableTreeNode("SWJHTZ");
DefaultMutableTreeNode t1_2 = new DefaultMutableTreeNode("WLYJ");
DefaultMutableTreeNode t2_1 = new DefaultMutableTreeNode("SPJC");
DefaultMutableTreeNode t2_2 = new DefaultMutableTreeNode("Java 3D");
JTree jTree = new JTree(root);
root.add(t1);root.add(t2);
t1.add(t1_1);t1.add(t1_2);
t2.add(t2_1);t2.add(t2_2);
JScrollPane scrollPane = new JScrollPane(jTree);
con.add(scrollPane);
setSize(200,300);
setLoction(500,100);
setVisible(true);
vildate();
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
public class Example{
public static void main(String[] args){
new Mytree("利用TreeNode构造树");
}
}