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?

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;
8 Years
Discussion Span
Last Post by falsedimitrii

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.