import java.io.IOException;
import javax.swing.*;
import javax.swing.tree.*;
class frame {
JFrame frame=new JFrame(); JTree t;
public void init() throws IOException{
String data[][]={{"zhang","20","boy"},{"li","19","girl"}};
String data1[][]={{"wang","21","boy"}};
String name[]={"姓名","年龄","性别"};
JTable zc=new JTable(data,name);
JScrollPane tabscr=new JScrollPane(zc);
//JTable zc1=new JTable(data1,name);
//JScrollPane tabscr1=new JScrollPane(zc);
DefaultMutableTreeNode first=new DefaultMutableTreeNode("班级结点");
DefaultMutableTreeNode second1=new DefaultMutableTreeNode("1班");
DefaultMutableTreeNode second2=new DefaultMutableTreeNode("2班");
DefaultTreeModel dm=new DefaultTreeModel(first);
dm.insertNodeInto(second1, first, first.getChildCount());
dm.insertNodeInto(second2, first, first.getChildCount());
t=new JTree(dm);
JScrollPane scrollPane2=new JScrollPane(t);
scrollPane2.setAutoscrolls(true);
JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollPane2,tabscr);
sp.setDividerLocation(100);
frame.add(sp);
frame.setSize(400,300);
frame.setVisible(true);
}
}
public class TestTree{
public static void main(String args[]) throws IOException{
new frame().init();
}
}
import javax.swing.*;
import javax.swing.tree.*;
class frame {
JFrame frame=new JFrame(); JTree t;
public void init() throws IOException{
String data[][]={{"zhang","20","boy"},{"li","19","girl"}};
String data1[][]={{"wang","21","boy"}};
String name[]={"姓名","年龄","性别"};
JTable zc=new JTable(data,name);
JScrollPane tabscr=new JScrollPane(zc);
//JTable zc1=new JTable(data1,name);
//JScrollPane tabscr1=new JScrollPane(zc);
DefaultMutableTreeNode first=new DefaultMutableTreeNode("班级结点");
DefaultMutableTreeNode second1=new DefaultMutableTreeNode("1班");
DefaultMutableTreeNode second2=new DefaultMutableTreeNode("2班");
DefaultTreeModel dm=new DefaultTreeModel(first);
dm.insertNodeInto(second1, first, first.getChildCount());
dm.insertNodeInto(second2, first, first.getChildCount());
t=new JTree(dm);
JScrollPane scrollPane2=new JScrollPane(t);
scrollPane2.setAutoscrolls(true);
JSplitPane sp=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollPane2,tabscr);
sp.setDividerLocation(100);
frame.add(sp);
frame.setSize(400,300);
frame.setVisible(true);
}
}
public class TestTree{
public static void main(String args[]) throws IOException{
new frame().init();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货