我有一个JTable如下.

因此,当JTable仍处于编辑模式时(在Dividend列上有一个键盘光标闪烁),直接单击OK将不会将数据提交到表模型中.单击"确定"仅关闭对话框.
我需要显式按ENTER键,以便将数据提交到表模型中.
虽然JTable仍然处于编辑模式,但在关闭对话框之前,有什么方法可以告诉JTable说:"嘿,是时候将更改提交到模型中"
此对话框的源代码如下对话框源代码.jButton1ActionPerformed按下确定时,请查看执行的代码.
Gui*_*ume 16
我不确定它是否可行(拥有SCCE本来不错),但试试这个:
TableCellEditor editor = table.getCellEditor();
if (editor != null) {
editor.stopCellEditing();
}
Run Code Online (Sandbox Code Playgroud)
要使整个稳定在任何状态下(编辑与否)完全停止编辑,可以调用editingstopped:
table.editingStopped(new ChangeEvent(table));
Run Code Online (Sandbox Code Playgroud)
这样你就不必检查编辑器/状态/等。
表格停止编辑提供了两种方法。
编辑
文章示例:
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
Run Code Online (Sandbox Code Playgroud)
文章示例:
if (table.isEditing())
table.getCellEditor().stopCellEditing();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4781 次 |
| 最近记录: |