I want to enable/disable a table cell based on the contents of another cell. e.g. if the reference cell value is "true", then enable the cell, otherwise disable the cell. I have set up isCellEditable() to do this and it works if the reference cell already has a value when bringing the table up. But if the user changes the value, isCellEditable() does not get called and so the cell is not enabled/disabled. So I need to have isCellEditable() called when the reference cell value changes and use that to set the cell. something like:

setCellEditable(isCellEditable(row,column), row, column)

but I don't see a method like setCellEditable.
How is this done?

@Override
public boolean isCellEditable(int row, int column) {

  if (column == 3) {
        String value = (String) defaultTableModel.getValueAt(row, 3);
        if (value.equalsIgnoreCase("true")) {
                return true;
        }
        return false;
  }
}

Recommended Answers

All 2 Replies

isCellEditable() gets called by the table when you double click a cell to see whether or not to the editor should be invoked. If you want to respond to a data change immediately, you'll need to use a TableModelListener most likely.

isCellEditable() gets called by the table when you double click a cell...

Ah, this is what I did not know. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.