swing中JTable的使用方法
1 public static void main(String[] args) { 2 3 Student s1 = new Student("张三", "001", 0); 4 Student s2 = new Student("李四", "002", 1); 5 Student s3 = new Student("王五", "003", 0); 6 7 Vector<Object> row1 = new Vector<Object>(); 8 row1.add(s1.getName()); 9 row1.add(s1.getNumber()); 10 row1.add(s1.getAbsentTimes()); 11 12 Vector<Object> row2 = new Vector<Object>(); 13 row2.add(s2.getName()); 14 row2.add(s2.getNumber()); 15 row2.add(s2.getAbsentTimes()); 16 17 Vector<Vector<Object>> studentData = new Vector<Vector<Object>>(); 18 Vector<String> columnNames = new Vector<String>(); 19 20 studentData.add(row1); 21 studentData.add(row2); 22 23 columnNames.add("姓名"); 24 columnNames.add("编号"); 25 columnNames.add("缺考次数"); 26 27 JTable table = new JTable(studentData, columnNames); 28 29 JFrame f = new JFrame(); 30 31 JScrollPane scrollPane = new JScrollPane(table); 32 f.getContentPane().add(scrollPane, BorderLayout.CENTER); 33 f.setVisible(true); 34 f.setSize(500, 500); 35 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 36 37 }