Java – forces JTable to model “commit” data while still in edit mode

I have a JTable as follows

Therefore, when JTable is still in edit mode (a keyboard cursor flashes in the divide column), clicking OK directly will not submit the data to the table model Click OK to close the dialog box only

I need to explicitly press enter to submit the data to the tabular model

Although JTable is still in edit mode, is there any way to tell JTable to say "Hey, it's time to submit your changes to your model" before closing the dialog box

The source code of this dialog box is as follows: dialog box source code When you press OK, look at jbutton1actionperformed. In the execution code

Solution

I don't know if it will work (it would be good to have an SCCE), but try this:

TableCellEditor editor = table.getCellEditor();
if (editor != null) {
  editor.stopCellEditing();
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>