这是我更新表的代码:
private void UpdateTable() {
String sql = "SELECT * FROM product";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
summaryproductTable.setModel(DbUtils.resultSetToTableModel(rs));
}
这是由 Netbeans(7.3.1) 生成的代码,我添加了 isEditable 因为我遵循我在 stackoverflow 中找到的指令:
summaryproductTable = new javax.swing.JTable();
summaryproductTable.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
summaryproductTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null}
},
new String [] {
"type", "materialcode", "serialnumber", "status", "careof", "date", "name", "accountnumber", "contactnumber"
}
)
{public boolean isCellEditable(int row, int column){return false;}}
);
summaryproductTable.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
summaryproductTableMouseClicked(evt);
}
});
jScrollPane1.setViewportView(summaryproductTable);
*我刚刚通过反复试验注意到 JTable 不可编辑,但是当您调用 UpdateTable() 方法时,它再次变得可编辑。