AbstractTableModel setValueAt 未在 Jbutton 单击时触发
我有一个扩展 AbstractTableModel 的自定义 TableModel。
public class IndicatorPropertyTableModel extends AbstractTableModel
当您在可编辑单元格中键入新值然后移至另一个单元格时,我编写的 setValueAt 函数会适当触发。我遇到的问题是,对于最后一个可编辑单元格,用户将立即单击 JButton 继续。这不会触发 setValueAt 函数,因此不会保存数据。有没有一种好方法可以确保当用户在编辑单元格后立即点击按钮时始终存储该值?如果需要,请参考下面的 setValueAt 函数。
public void setValueAt(Object value, int row, int col) {
if (value == null)
return;
if (col == 0) {
//this.indicatorArguments[row].setIsSelected(value);
} else if (col == 2) {
this.indicatorArguments[row].setValue(value);
}
this.fireTableCellUpdated(row, col);
}
感谢您提供的任何帮助。
I have a custom TableModel that extends the AbstractTableModel.
public class IndicatorPropertyTableModel extends AbstractTableModel
The setValueAt function I wrote fires appropriately in cases when you type a new value into the editable cell and then move on to another cell. The problem I am having is that for the last editable cell the user will immediately click a JButton to continue. This does not trigger the setValueAt function thus not saving the data. Is there a good way to ensure that this value is always stored when a user immediately hits a button after editing a cell? setValueAt function below for reference if needed.
public void setValueAt(Object value, int row, int col) {
if (value == null)
return;
if (col == 0) {
//this.indicatorArguments[row].setIsSelected(value);
} else if (col == 2) {
this.indicatorArguments[row].setValue(value);
}
this.fireTableCellUpdated(row, col);
}
Thanks for any help you can provide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设你的按钮在桌子外面。
在按钮的事件侦听器或操作中,您需要对该表的引用。然后您可以询问该表是否 isEditing 返回 true。然后您将 获取当前编辑器 并在验证最后一个输入值后调用 stopCellEditing 提交值或 cancelCellEditing 撤消该值。
简而言之:
总是提交尚未输入的值。
I assume that your button is outside the table.
In the event listener or action of your button you would need a reference to the table. This table you could then ask whether isEditing returns true. Then you would get the current editor and after validating the last input value either call stopCellEditing to commit the value or cancelCellEditing to undo the value.
In short:
would always commit not yet entered values.
检查表是否正在编辑需要您向 GUI 上的所有按钮添加代码。
您也许可以使用一种简单的单行解决方案来避免这种情况。查看表格停止编辑。
Checking if the table is editing requires you to add code to all buttons on your GUI.
You may be able to use a simple one line solution that avoids this. Check out Table Stop Editing.