swing中JTable的初级使用
//参照CSDN::http://blog.csdn.net/xinem/article/details/3855737
//实图:::
//代码::
1 /** 2 * 3 */ 4 package com.breaver.jtable; 5 6 import java.awt.Dimension; 7 import java.awt.FlowLayout; 8 import java.awt.HeadlessException; 9 10 import javax.swing.JFrame; 11 import javax.swing.JScrollPane; 12 import javax.swing.JTable; 13 import javax.swing.table.DefaultTableModel; 14 15 /** 16 * @author zzf 17 *@date 2017年6月20日 上午9:17:18 18 */ 19 public class TableJFrame extends JFrame { 20 DefaultTableModel defaultTableModel = new DefaultTableModel(); 21 JTable jTable = new JTable(); 22 String title_tale[]={"ID","name","password","sex","phone"}; 23 String rows1[]={"2","xiaowang","123","1","10086"}; 24 JScrollPane jScrollPane = new JScrollPane(jTable); 25 /** 26 * @param args 27 */ 28 29 public static void main(String[] args) { 30 // TODO Auto-generated method stub 31 new TableJFrame(); 32 } 33 34 public TableJFrame() throws HeadlessException { 35 super(); 36 // TODO Auto-generated constructor stub 37 this.setSize(new Dimension(600, 600)); 38 this.setLocationRelativeTo(null); 39 this.setTitle("如何使用jtable"); 40 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 41 //---------------------------------------- 42 // defaultTableModel.addRow(title_tale); 43 // defaultTableModel.addRow(rows1); 44 jTable.setModel(defaultTableModel); 45 this.getContentPane().add(jScrollPane); 46 this.getContentPane().setLayout(new FlowLayout()); 47 for(String string:title_tale) 48 defaultTableModel.addColumn(string); 49 defaultTableModel.addRow(rows1); 50 51 //------------------------------------------- 52 this.setVisible(true); 53 } 54 55 }