Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force cell editor in jtable to accept edits

Tags:

java

jtable

i have a jtable with multiple editable cells

when someone presses the "save button" on the menu, it doesn't save the last value that is still currently being edited. (unless they tab out of the cell first)

i can check it is being edited by calling .isEditing() which returns true.

What i would prefer to do is trigger that the cell editing is complete, and it can show any validation errors, and if none, then save. (without the user having to tab out first)

can someone please point me in the right direction

thanks

like image 634
bumperbox Avatar asked Dec 13 '22 11:12

bumperbox


1 Answers

You can manually call:

JTable table;
table.getCellEditor().stopCellEditing();

This should cause the table to stop editing at that cell. By overriding the stopCellEditing() method of your TableCellEditor and returning false under certain circumstances, you can indicate that the cell's value is currently invalid and thus editing cannot be stopped at that time.

like image 81
Mark Peters Avatar answered Feb 14 '23 13:02

Mark Peters