Can i add an UndoableEditListener to a JTable? For example with a JTextField we do this :
textField = new JTextField();
Document doc = textField.getDocument();
doc.addUndoableEditListener(new MyUndoableEditListener());
You can do that for CellEditor
of the JTabel
in next way:
use DefaultCellEditor
with JTextField
:
JTextField field = new JTextField();
field.getDocument().addUndoableEditListener(new UndoableEditListener() {
@Override
public void undoableEditHappened(UndoableEditEvent arg0) {
System.out.println("profit");
}
});
DefaultCellEditor editor = new DefaultCellEditor(field);
table.getColumnModel().getColumn(COLUMN_INDEX).setCellEditor(editor);
table
is your JTable
and COLUMN_INDEX
index of needed column.