Which listener can be used to react to the event of JTable cell value change? I tried using TableModelListener but either I got something wrong, or this listener doesn't react on changing the contents of a cell.
I need to act either to changing the content of a cell or to cell losing focus. What is the best way to do this? Thanks.
class extends JTable {
.... (inside contructor)
addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if ("tableCellEditor".equals(evt.getPropertyName())) {
if (isEditing())
processEditingStarted();
else
processEditingStopped();
}
}
});
... (end constructor)
protected void processEditingStopped() {
System.out.println("save " + editingRow + ":" + editingColumn);
}
protected void processEditingStarted() {
System.out.println("edit " + editingRow + ":" + editingColumn);
if (editRow > -1 && editColumn > -1)
oldValue = (String) model.getValueAt(editRow, editColumn);
}
}
more details here: http://tips4java.wordpress.com/2009/06/07/table-cell-listener/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With