views:

39

answers:

1

I currently have a problem whereby editing the contents of one cell in a JTable alters the content of another; 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.

Has anyone got any tips or suggestions?

+1  A: 

It sounds like you should be using a TableModelListener to listen for changes to the TableModel. When a checkbox is changed you will receive an update event and you would then update the other checkbox by using model.setValueAt(...). The model is responsible for notifying the view to repaint the cell.

camickr
I've added a TableModelListener to the TableModel. However, it only seems to fire when an object is added/deleted, rather than when attributes of the object are changed... any ideas?
colinjameswebb
The default table editor does not modify an Object it always creates a new Object (String, Date, Integer) depending on the class of the column. If you are using a custom editor then I don't know what your code is doing. If you need more help post your http://sscce.org (SSCCE) that demonstrated the problem.
camickr