JTable stop cell editing without user click

倖福魔咒の 提交于 2019-11-29 12:49:20
camickr

My problem is that once a user updates a cell and clicks "finished" the last updates made do not work.

Check out Table Stop Editing for two approaches:

You can either:

Add code to the ActionListener:

if (table.isEditing())
     table.getCellEditor().stopCellEditing();

or set a property on the table:

JTable table = new JTable(...);
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

Edit:

When the user clicks finished all the cell data will be saved to a 2D array.

Why? All the data is already stored in the TableModel.

In any case you need to stop editing BEFORE you attempt to copy data from the TableModel to the Array.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!