What is the appropriate method to detect changes made to an entity through an editable cell in a JTable? I would like to get the entity which the changes occurred so that I can commit the changes using JPA (eclipselink).
So far I tried a TableModelListener implementation. However, it seems that the TableModelEvent does not provide a reference to the underlying entity (or data provider of the table) object but only to the value (Object) which has changed.
Having a background in AS3, I’m used to writing event driven code. But, what is the right approach to implement this in Java?
Either inspect the row of the TableModelEvent fired by the modification, and ask your model the entity at this row, or fire another dedicated event when a cell is updated, containing the updated entity.
See the Swing tutorial on tables for how to create your own table model, extending AbstractTableModel. It’s almost always better than using the default one, and I thought you were doing it already, because you said that “changes [were] made to an entity through an editable cell”.