求大神看一个JTable和JTree结合的问题。。。。
我不清楚怎么实现点一班出现一班同学的数据 点二班出现二班的,我觉得应该是在易做图里实现 但是我不会 求大神在我的代码里帮我指导下
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 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();
}
}
补充:Java , Java SE