sethu
sethu

Reputation: 8431

Cancel a Table Update Event in Swing

I have a case where I would like to catch an update event on a table, check what the current value is and what the new value would be for the affected column + row. If its not what is expected, I would like cancel the update and revert it back to what it was. This is incredibly hard to do with the TableModelListener and I keep running into stack overflow errors, because I am unable to manually maintain the state and revert it back without it recursively calling itself again.

Upvotes: 1

Views: 358

Answers (1)

Kylar
Kylar

Reputation: 9334

Create your own TableModel (or extend DefaultTableModel or AbstractTableModel), and override setValueAt - in there, you can either update the underlying model (with super.setValueAt()) or throw it away - you don't need to save the old value, because the change will never go through unless you call the superclass.

Upvotes: 3

Related Questions