简体   繁体   English

JTable中的互斥单元格编辑器

[英]Mutually Exclusive CellEditors in JTable

I currently have a problem whereby editing the contents of one cell in a JTable alters the content of another; 我目前遇到一个问题,即编辑JTable中一个单元格的内容会改变另一个单元格的内容。 two of the columns are mutually exclusive. 其中两列是互斥的。 They are both checkboxes. 它们都是复选框。

At the moment, if I alter one cell, it isn't until the other is redrawn that it updates. 目前,如果我更改一个单元格,则直到另一个单元格被重绘时,它才会更新。 Therefore, both cells in the row can be displayed as being selected at any one time. 因此,该行中的两个单元格都可以显示为随时选择。 This can be overcome by calling updateUI(), but it is slow and not a generally great idea. 可以通过调用updateUI()来克服,但这很慢,而且不是一个好主意。

Has anyone got any tips or suggestions? 有没有人得到任何提示或建议?

It sounds like you should be using a TableModelListener to listen for changes to the TableModel. 听起来您应该使用TableModelListener来监听对TableModel的更改。 When a checkbox is changed you will receive an update event and you would then update the other checkbox by using model.setValueAt(...). 更改复选框后,您将收到一个更新事件,然后您将使用model.setValueAt(...)更新另一个复选框。 The model is responsible for notifying the view to repaint the cell. 该模型负责通知视图以重新绘制单元格。

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

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