如何强制 jtable 中的单元格编辑器接受编辑
我有一个包含多个可编辑单元格的 jtable,
当有人按下菜单上的“保存按钮”时,它不会保存当前仍在编辑的最后一个值。 (除非他们先跳出单元格)
我可以通过调用 .isEditing() 返回 true 来检查它是否正在编辑。
我更喜欢做的是触发单元格编辑完成,并且它可以显示任何验证错误,如果没有,则保存。 (用户无需先退出)
有人可以指出我正确的方向吗?
谢谢
i have a jtable with multiple editable cells
when someone presses the "save button" on the menu, it doesn't save the last value that is still currently being edited. (unless they tab out of the cell first)
i can check it is being edited by calling .isEditing() which returns true.
What i would prefer to do is trigger that the cell editing is complete, and it can show any validation errors, and if none, then save. (without the user having to tab out first)
can someone please point me in the right direction
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以手动调用:
这应该会导致表格在该单元格处停止编辑。通过重写
TableCellEditor
的stopCellEditing()
方法并在某些情况下返回 false,您可以指示单元格的值当前无效,因此此时无法停止编辑。You can manually call:
This should cause the table to stop editing at that cell. By overriding the
stopCellEditing()
method of yourTableCellEditor
and returning false under certain circumstances, you can indicate that the cell's value is currently invalid and thus editing cannot be stopped at that time.当你有一个包含多个可编辑单元格的jtable时
,当有人按下菜单上的“保存按钮”时,它不会保存最后一个值,那么请添加下面的代码:
第一个是让表自动停止编辑并保存数据。这可以通过在表上设置属性来完成:
它将确保当有人按下菜单上的任何按钮时,它也会保存最后编辑的值。
when you have a jtable with multiple editable cells
when someone presses the "save button" on the menu, it doesn't save the last value then please add the below peace of code
The first is to have the table automatically stop editing and save the data. This can be done by setting a property on the table:
It will make sure that when someone presses the any button on the menu, it saves the last edited value also.
如果我没记错的话,编辑/添加的值默认存在于单元格编辑器组件中,它是 EditBox,但不存在于表格模型中。如果可以尝试检查单元格编辑器组件它应该对您有帮助。
If I remember correctly, edited/added value is present in cell editor component by default it is EditBox, BUT do not present in table model. If it is possible try to check cell editor component it should help you.