问题描述
我不清楚怎么实现点一班出现一班同学的数据点二班出现二班的,我觉得应该是在监听器里实现但是我不会求大神在我的代码里帮我指导下
importjava.io.IOException;importjavax.swing.*;importjavax.swing.tree.*;classframe{JFrameframe=newJFrame();JTreet;publicvoidinit()throwsIOException{Stringdata[][]={{"zhang","20","boy"},{"li","19","girl"}};Stringdata1[][]={{"wang","21","boy"}};Stringname[]={"姓名","年龄","性别"};JTablezc=newJTable(data,name);JScrollPanetabscr=newJScrollPane(zc);//JTablezc1=newJTable(data1,name);//JScrollPanetabscr1=newJScrollPane(zc);DefaultMutableTreeNodefirst=newDefaultMutableTreeNode("班级结点");DefaultMutableTreeNodesecond1=newDefaultMutableTreeNode("1班");DefaultMutableTreeNodesecond2=newDefaultMutableTreeNode("2班");DefaultTreeModeldm=newDefaultTreeModel(first);dm.insertNodeInto(second1,first,first.getChildCount());dm.insertNodeInto(second2,first,first.getChildCount());t=newJTree(dm);JScrollPanescrollPane2=newJScrollPane(t);scrollPane2.setAutoscrolls(true);JSplitPanesp=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollPane2,tabscr);sp.setDividerLocation(100);frame.add(sp);frame.setSize(400,300);frame.setVisible(true);}}publicclassTestTree{publicstaticvoidmain(Stringargs[])throwsIOException{newframe().init();}}
解决方案
解决方案二:
importjava.io.IOException;importjavax.swing.*;importjavax.swing.tree.*;classframe{JFrameframe=newJFrame();JTreet;publicvoidinit()throwsIOException{Stringdata[][]={{"zhang","20","boy"},{"li","19","girl"}};Stringdata1[][]={{"wang","21","boy"}};Stringname[]={"姓名","年龄","性别"};JTablezc=newJTable(data,name);JScrollPanetabscr=newJScrollPane(zc);//JTablezc1=newJTable(data1,name);//JScrollPanetabscr1=newJScrollPane(zc);DefaultMutableTreeNodefirst=newDefaultMutableTreeNode("班级结点");DefaultMutableTreeNodesecond1=newDefaultMutableTreeNode("1班");DefaultMutableTreeNodesecond2=newDefaultMutableTreeNode("2班");DefaultTreeModeldm=newDefaultTreeModel(first);dm.insertNodeInto(second1,first,first.getChildCount());dm.insertNodeInto(second2,first,first.getChildCount());t=newJTree(dm);JScrollPanescrollPane2=newJScrollPane(t);scrollPane2.setAutoscrolls(true);JSplitPanesp=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollPane2,tabscr);sp.setDividerLocation(100);frame.add(sp);frame.setSize(400,300);frame.setVisible(true);}}publicclassTestTree{publicstaticvoidmain(Stringargs[])throwsIOException{newframe().init();}}
解决方案三:
有大神帮我一下吗????????????