Search code examples
javaswingjtablejcheckbox

isCellEditable true for a particular row on checkbox selected when isCellEditable false on checkbox deselected


enter image description here

I want disable editing Column 1 to Column 9 when Column 0 CheckBox is false and Checkbox value is true enable editing Column 1 to Column 9 when Column 0....How to do that?


Solution

  • You need to override the isCellEditable method from the TableModel...for example

    public boolean isCellEditable(int rowIndex, int columnIndex) {
        boolean isEditable = false;
        if (columnIndex >= 1 && columnIndex <= 9) {
            Object value = getValueAt(rowIndex, 0);
            if (value instance Boolean) {
               isEditable = !((boolean)value);
            } 
        } else {
            // Other columns...
        }
        return isEditable
    }
    

    Check out TableModel and How to use tables for more details...