I'm building and app with multiple JTables
and I need to detect when cell value change occurs so I can update it in the database. I tried TableModelListener
and overriding tableChanged
, but it fires only when I click away (click on another row) after I have edited a cell.
Any other way to do this?
You can implement the CellEditorListener
interface, as shown in this example. Note that JTable
itself is a CellEditorListener
.
It may also be convenient to terminate the edit when focus is lost, as shown here:
table.putClientProperty("terminateEditOnFocusLost", true);
More Swing client properties may be found here.