Hello All, i want to have a Jtable where in one column i want to be checkbox. i.e. If i make the cell editor checkbox, then only when i click ,i will see the checkbox,i will see the value true or false. so,now i want the checkbox to be displayed always How do i do this!!! Thanks and Regards vinaa
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.
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);
}
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.
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.
Thanks, but I know these examples, they are far to complicated for what I want to do... I mean, I hoped there where simpler ways.. A table with just one column checkboxes? Oh, there are times I wish for Visual Basic! (wrong thing to say here, suppose..) So there is no one-liner like: jTable1.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor (new JCheckBox())); ?
What's the difference? I'm using "new Boolean(false)" at the moment. In the meantime, I worked out that the main problem is, that my rows are Vectors, but the colums are Arrays. So I hope it will work when I fixed that... Thanks!