I have a JTable using a custom DefaultTableModel which has some Booleans in the last column (displayed as tick boxes).
When I add a MouseListener to retrieve the value of what's been clicked it appears that the toggling of tick boxes no longer takes place.
// As soon as this is used in the component
// that is using the JTable, the toggling stops
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
int col = table.getSelectedColumn();
int row = table.getSelectedRow();
Object o = table.getModel().getValueAt(row, col);
I assume that the event is being consumed by the listener. What can I add to the MouseListener code to restore the toggling behaviour?
Edit:
Oops, it appears that the issue lies with my override:
@Override
public void setValueAt(Object aValue, int row, int column) {
// Attempt at mutually exclusive checkboxes
if( column == 2 ){ // Starts at 0. Seek an alternative solution to avoid hardcoding?
// Algorithm: cycle through List to set other Booleans to false
// Uses entities. Is there another way of getting the number of rows from model?
List<MyEntity> myEntities = this.getDatas();
for( int i = 0; i < myEntities.size(); i++ ){
if( i != row ){
// Make sure this calls parent
super.setValueAt( false , i, 2);
}
}
} else {
super.setValueAt(aValue, row, column); // Call parent class
}
}