javax.swing.table.DefaultTableModel
This is an implementation of TableModel
that uses a Vector
of Vectors
to store the cell value objects.
例子:
DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
dtm.setRowCount(0); //每次重新填充前先清空
Connection con = null;
try {
con = dbUtil.getCon();
ResultSet rs = ticketInformDao.getInformtList(con, ticket_Inform);
while (rs.next()) {
Vector v = new Vector(); //不能放在while外面,以保证添加的都是不同的对象。因为对象在做参数时都是传递的地址
v.add(rs.getInt("userId"));
v.add(rs.getString("ticket_Name"));
v.add(new school()); //可以添加任何不同的类型,很方便
v.add(rs.getDouble("number"));
v.add(rs.getString("inOrOut"));
v.add(rs.getDate("time"));
dtm.addRow(v); //最后一句就可以把所有数据添加到这一行中了,好用