1
  1. I set the renderer to the checkbox on jtable using following code

    Object[] ColumnData = {"Sr No","Ward Name","Total voters","Action"};
    Object[][] RawData=null;
    

    // in loop

    model.insertRow(x, new Object[]{ key,ward_name_var,total_vot_var,new Object[]{o}}); model.setValueAt(o,x,3); tblWard.setModel(model);

    Setchk(tblWard,3,checkbox); // by calling this method which contains following

    private void Setchk(JTable jTable1, int i, JCheckBox checkbox) { jTable1.getColumnModel().getColumn(i).setCellRenderer((new CWCheckBoxRenderer())); jTable1.getColumnModel().getColumn(i).setCellEditor(new CheckBoxCellEditor()); }

Blockquote

how can we try it for row to set the checkbox on jtable. thanks in advance.

Pavan Gomladu
  • 66
  • 1
  • 8
  • 2
    What do you mean with 'set a renderer for a row'. The used renderer depends on the data in a specific cell (for example an integer requires a different renderer then a boolean), and this data has the same type in each column. So it only make sense to set a renderer for a column, and not for a row – Robin Mar 28 '12 at 10:16

2 Answers2

2

If your data is of type Boolean.class, the default render will display a checkbox. To change the checkbox in a particular row, you need a corresponding CellEditor. The default render/editor are used here; custom components are illustrated here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
1

You can simply override the getCellRenderer method of your JTable to return the desired renderer for a given row. Example:

JTable table = new JTable() {
    TableCellRenderer getCellRenderer(int row, int column) {
        if (row == checkBoxRow)
            return myCheckBoxRenderer;
        else
            return super.getCellRenderer(row, column);
    }
};
cgull
  • 1,407
  • 1
  • 11
  • 18