JTable Data not saved

I have JTable in a GUI and a button to save the data in the table to a database. The JTable's view and model are separate. When I do a save, the data in the last cell which I edited is lost.

Only if I change the focus to a different cell or if I press ENTER key, it fires an event to update the cell (i.e. it calls the "setValue" method in the data model). Without this, how can I fire an event to update the data in the cell.
bonk1Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vladi21Connect With a Mentor Commented:
yes its
stopCellEditing();

I have written it in the evening escaping with work and on a road has recollected that was not exact slightly
:)
0
 
vladi21Commented:
call cancelEditing()
0
 
vladi21Commented:
if (isEditing()) myDefaultCellEditor.cancelCellEditing();

or

 if (isEditing()) getDefaultEditor(String.class).cancelCellEditing();
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
bonk1Author Commented:
Calling cancelCellEditing causes the orgional value to be placed back into the cell that is currently being edited.  This does not call setValueAt() for my TableModel.

0
 
bonk1Author Commented:
I think what I need to do is call fireEditingStopped() of the default cell editor. But that function is protected and I can't find information on how to properly setup a new DefaultCellEditor.
0
 
bonk1Author Commented:
Calling cancelCellEditing causes the orgional value to be placed back into the cell that is currently being edited.  This does not call setValueAt() for my TableModel.

0
 
bonk1Author Commented:
Ok here's the answer. It's not cancelCellEditing() but it's stopCellEditing().  Thanks, anyways.  I guess you pushed me in the right direction.

0
All Courses

From novice to tech pro — start learning today.