1
votes
  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.

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 rowRobin

2 Answers

2
votes

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.

1
votes

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);
    }
};