Hi!
My question is how could I add the checkbox column to my table. Well, I've tried the following solution, however it provides error message (null), if the table field is empty:
tableModel = new QueryTableModel();
tableAttributesFormTypes = new JTable();
tableAttributesFormTypes.setModel(tableModel);
tableModel.setQuery("select at_code, at_title, at_type from Attributes");
class QueryTableModel extends AbstractTableModel {
...
public Class getColumnClass(int col) {
return getValueAt(0, col).getClass();
}
...
public void setQuery(String q) {
cache = new Vector();
try {
// Execute the query and store the result set and its metadata
ResultSet rs = statement.executeQuery(q);
ResultSetMetaData meta = (ResultSetMetaData) rs.getMetaData();
colCount = meta.getColumnCount();
headers = new String[colCount];
for (int h = 1; h <= colCount; h++) {
headers[h - 1] = meta.getColumnName(h);
}
while (rs.next()) {
String[] record = new String[colCount];
for (int i = 0; i < colCount; i++) {
record[i] = rs.getString(i + 1);
}
cache.addElement(record);
}
fireTableChanged(null);
} catch (Exception e) {
cache = new Vector();
System.out.println(e.getMessage()); // THIS EXCEPTION IS EXECUTED!!!
}
}
}
So, how could I change my code to allow empty fields in the table?! Thanks!