简体   繁体   English

如何处理JTable数据更改事件

[英]How to handle JTable data changed event

I have a JTable bound to a List property. 我有一个绑定到List属性的JTable。 I used NetBeans to add a property to my jpanel form, enabled/checked propertyChangeSupport, and bound my jTable to that property. 我使用NetBeans将属性添加到我的jpanel表单中,启用/选中了propertyChangeSupport,然后将jTable绑定到该属性。 Table is displaying the data perfectly. 表完美显示数据。 Please guide me how can I enable/disable a 'Save' button when data of this table is changed by double-clicking a cell and editing its contents. 请指导我如何通过双击单元格并编辑其内容来更改/禁用此表的数据时的“保存”按钮。

The Table Cell Listener will listen for real changes in the data of a cell. 表单元侦听器将侦听单元数据中的实际更改。

A TableModelListener fires an event even if you tab out of the cell and don't actually change the data. 即使您跳出单元格并且实际上不更改数据,TableModelListener也会触发事件。

Have you tried adding a TableModelListener to the JTable's model? 您是否尝试过将TableModelListener添加到JTable的模型中? This should fire any time the table's data is changed, and the listener can then enable your save button. 只要更改表的数据,就会触发该事件,然后侦听器可以启用您的保存按钮。 The button should disable itself whenever it is pressed and the data has been successfully saved. 只要按下该按钮并且数据已成功保存,该按钮应自行禁用。

Edit: 编辑:
Please ignore this and instead go with camickr's recommendation! 请忽略此内容,而是接受camickr的推荐!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM