我创建了一个将数据加载到JTable
. 一切正常,只是此表中的所有单元格都是可编辑的。顺便说一句,我用于defaultTableModel
表格模型。我在 Netbeans IDE 中这样做。请帮忙。这是我的代码:
private void updateTable(String searchText){
if(searchText != null)
this._sqlCmd = this._sqlCmd + " WHERE "+columnCombo.getSelectedItem()+" LIKE '%"+searchText+"%'";
jTable1.setSurrendersFocusOnKeystroke(true);
table = (javax.swing.table.DefaultTableModel) jTable1.getModel();
try{
table.setRowCount(0);
}catch(Exception e){}
try {
ResultSet rs = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY).executeQuery(_sqlCmd);
while (rs.next()){
Object[] data = new Object[numOfCols];
for(int i=0; i<data.length; i++){
data[i] = rs.getObject(i+1);
}
table.addRow(data);
}
table.fireTableDataChanged();
} catch (SQLException ex) {
Logger.getLogger(FindContactGrid.class.getName()).log(Level.SEVERE, null, ex);
}
}