All I really need is a function to call when the checkbox is selected.
When checked, the value will be changed in the model, which is probably not the way you want. I would think that you want to prevent the checkbox from being checked first.
A way to prevent cell editing is to override the isCellEditable (...) JTable method. By overriding this method, you can dynamically determine whether a cell should be editable or not.
JTable table = new JTable( ... ) { public boolean isCellEditable(int row, int column) { int modelColumn = convertColumnIndexToModel( column ); if (modelColumn == yourBooleanColumn) return isTheBooleanForThisRowEditable(row); else return super.isCellEditable(row, column); } };
And it would be more attractive to create a custom visualization tool so that the checkbox is disabled even before the user tries to click on the cell. See the link provided by trashgod on the renderers.
source share