Hi,
I would be happy enought to have combo boxes instead of checkboxes. So what I'm doing is:
public class DBdetailTableModel extends AbstractTableModel {
....
public DBdetailTableModel(Connection connection)
{
this.connection = connection;
}
public void executePrepStmt(PreparedStatement prepStmt)
{
if (connection == null || prepStmt == null) {
System.err.println("There is no database to execute the query.");
return;
}
try {
resultSet = prepStmt.executeQuery();
metaData = resultSet.getMetaData();
int numberOfColumns = 6; columnNames = new String[numberOfColumns];
columnNames[0] = "Sample_Id";
.....
columnNames[5] = "Yes/NO
......
while(resultSet.next())
{
...
newRow[5]= new Boolean(false); .......
public boolean isCellEditable(int row, int column)
{
if (column == 5)
return true;
else
return false;
}
}
And in the GUI class:
dt = new DBdetailTableModel(connection);
jTable1 = new JTable(dt);
PreparedStatement prepStm = dt.connection.prepareStatement(query);
dt.executePrepStmt(prepStm);
jTable1.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor (new JCheckBox()));
But I see the checkBox only when I'm trying to edit the cell, otherwise it says just "false".
Could you help me?
Originally posted by Anuradha Saravanamuthu:
Hi vinay,
If u initialize ur table model with the boolean object value , by default jtable will put the combo box. The problem with this is it is selectable only with mouse. So, u can add custom checkbox editor and renderer to make the checkbox being selectable on tab key moment and selection on spacebar.
thanx & regards,
S.A.Radha.