以下是我更新表格的代码:
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()方法时它再次变得可编辑。
答案 0 :(得分:0)
在NetBeans中 右键单击表格 - >属性 - >在复选框中选中可编辑 让它未被选中 简单....