开发工具:
文件大小: 10kb
下载次数: 0
上传时间: 2011-08-11
详细说明: package BookTest; import java.awt.*; import java.awt.event.*; import java.util.AbstractQueue; import java.util.Vector; import javax.swing.*; import javax.swing.table.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeSelectionModel; import javax.swing.event.*; import javax.swing.table.TableColumnModel; //import DbHelp.OperatorJobs; import Dao.ArrayBook; public class Test extends JFrame { public JPanel jp=null; public String aa; //JTable jTable1 = new JTable(); public JTable jTable1=null; private JTree jTree1; DefaultTableModel mode; private JScrollPane scrollPane = null; DefaultMutableTreeNode node; JButton[] btn={new JButton("增加"),new JButton("删除"),new JButton("修改"),new JButton("查询"),new JButton("重置")}; public JTextField[] txt ={new JTextField(),new JTextField(),new JTextField(),new JTextField(),new JTextField(),new JTextField()}; public String[] str1={"1","summer","boy","20","",""}; public String[] str2={"2","wulei","girl","19","",""}; public String[] str3={"3","west","boy","20","",""}; public String[] str4={"4","fish","girl","18","",""}; public String[] str5={"5","youku","boy","21","",""}; public String[] str6={"6","aa","boy","21","",""}; public String[][] tempData1={str1,str2,str3,str4,str5,str6}; public String[] aa1={"1","summer","boy","20","123","123"}; public String[] aa2={"2","wulei","girl","19","123",""}; public String[] aa3={"3","west","boy","20","123",""}; public String[] aa4={"4","fish","girl","18","1",""}; public String[] aa5={"5","youku","boy","21","12",""}; public String[] aa6={"6","aa","boy","21","123",""}; public String[][] tempData4={aa1,aa2,aa3,aa4,aa5,aa6}; //设置表头数据 public String[] tempTitle={"ID","标题","内容","作者","时间","是否选中"}; //设置表格的数据集合 Vector v1=new Vector(); Vector v2=new Vector(); Vector v3=new Vector(); Vector v4=new Vector(); Vector v5=new Vector(); Vector v6=new Vector(); Vector rows=new Vector(); //设置表头数据集合 Vector[] tempData2={v1,v2,v3,v4,v5,v6}; Vector data=new Vector(); Vector title=new Vector(); Vector data1=new Vector(); Vector v=new Vector(); DefaultTableModel model; public Test() { this.setSize(800,600); JPanel jp=(JPanel)this.getContentPane(); jp.setLayout(null); jp.setBorder(BorderFactory.createTitledBorder("JTable和JTree")); DefaultMutableTreeNode root = new DefaultMutableTreeNode("图书"); DefaultMutableTreeNode node1=new DefaultMutableTreeNode("java"); DefaultMutableTreeNode node2=new DefaultMutableTreeNode("jsp"); DefaultTreeModel treeModel=new DefaultTreeModel(root); treeModel.insertNodeInto(node1, root, root.getChildCount()); treeModel.insertNodeInto(node2, root, root.getChildCount()); DefaultMutableTreeNode leafnode=new DefaultMutableTreeNode("aa"); treeModel.insertNodeInto(leafnode, node1, node1.getChildCount()); leafnode=new DefaultMutableTreeNode("bb"); treeModel.insertNodeInto(leafnode, node1, node1.getChildCount()); leafnode=new DefaultMutableTreeNode("cc"); treeModel.insertNodeInto(leafnode, node1, node1.getChildCount()); leafnode=new DefaultMutableTreeNode("dd"); treeModel.insertNodeInto(leafnode, node1, node1.getChildCount()); leafnode=new DefaultMutableTreeNode("dd"); treeModel.insertNodeInto(leafnode, node2, node2.getChildCount()); leafnode=new DefaultMutableTreeNode("ee"); treeModel.insertNodeInto(leafnode, node2, node2.getChildCount()); JTree jTree1=new JTree(treeModel); jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); jTree1.setRowHeight(20); jTree1.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { jTree1ValueChanged(evt); } }); DefaultTreeCellRenderer cellRenderer=(DefaultTreeCellRenderer)jTree1.getCellRenderer(); cellRenderer.setTextNonSelectionColor(Color.black); cellRenderer.setTextSelectionColor(Color.blue); jTree1.setBounds(10,20,150,600); jp.add(jTree1); for(int i=0;i0;i--){ mode.removeRow(0); } model= new DefaultTableModel(new Object[]{"书籍编号","图书类别","书名","作者","价钱","ISBN"}, 0); JTree jTree1=(JTree)e.getSource(); jTable1.setModel(model); jTable1=new JTable(model); DefaultMutableTreeNode node=(DefaultMutableTreeNode)jTree1.getLastSelectedPathComponent(); String nodeName=node.toString(); Vector ve = this.GetBookByCname(nodeName.toString()); for (int i = 0; i < ve.size(); i++) { String[] row = (String[]) ve.get(i); model.addRow(row); } // }else if(nodeName.toString().equals("bb")){ // System.out.print("bb"); // }else{ // System.out.print("cc"); // } } public Vector GetBookByCname(String cname){ Vector v=this.All(); Vector vector=new Vector(); for(int i=0;i0){ JOptionPane.showMessageDialog(this.tf,"请选择您要准备删除的数据行!"); this.tf.data.remove(index);//在TableFrame中Vector data 加入删除该行数据 }else if(index==0){ this.tf.data.remove(index);//在TableFrame中Vector data 加入删除该行数据 this.tf.btn[1].setEnabled(false);//表格中的数据删除,"删除"按钮失效 }else{ JOptionPane.showMessageDialog(this.tf,"请选择您要准备删除的数据行!"); } refreshTable(); } public void update(){ Vector v=this.setVector();//从文本框中取得需要修改的内容 int index=this.tf.jTable1.getSelectedRow();//返回选中行的索引 if(index<0){ JOptionPane.showMessageDialog(this.tf,"请选择您要准备删除的数据行!"); }else{ this.tf.data.set(index,v); refreshTable();//刷新表格模型 } } public void select(){ for(int i=0;i
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.