建立一个系统默认的简单树结构
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了建立一个系统默认的简单树结构相关的知识,希望对你有一定的参考价值。
/*最简单的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构造树");
}
}
以上是关于建立一个系统默认的简单树结构的主要内容,如果未能解决你的问题,请参考以下文章