开发者

Force JTable to "commit" data to model while it is still in editing mode

I have a JTable as follow.

Force JTable to "commit" data to model while it is still in editing mode

So, while the JTable is still in editing mode (There is a keyboard cursor blinking at Dividend column), clicking OK directly will not commit the data into table model. Clicking OK merely close the dialog box.

I need to press EN开发者_开发问答TER explicitly, in order to commit the data into table model.

While JTable is still in editing mode, before closing dialog box, is there any way I can tell the JTable by saying, "Hey, is time for you to commit the changes into your model"

The source code for this dialog box is as follow Dialog Box Source Code. Do look at jButton1ActionPerformed for the executed code when OK is pressed.


I'm not sure if it will work (it would have been nice to have a SCCE), but try this:

TableCellEditor editor = table.getCellEditor();
if (editor != null) {
  editor.stopCellEditing();
}


Table Stop Editing gives a couple of approaches.

EDIT

Example from article:

table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

Example from article:

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


To make the whole stable stop editing completely in any state (editing or not), you can call editing stopped:

    table.editingStopped(new ChangeEvent(table));

That way you don't have to check for editors/state/etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜