Check Validation Notification in JTable

I searched for this for quite some time and did not find a clear example anywhere. I am a newbie Java using NetBeans. I have a boolean in the first column of JTable (called "Enabled"), and I have some plug-in code that I need to call to find out if it has the parameters it needs to enable, and if not, the message box and disable Enabled check.

I really need the function to be called when the checkbox is checked, and I can take it from there. Does anyone have an example of how to do this?

Thank you for your help!

Harry

+4
source share
2 answers

You probably want a TableModelListener , as described in Listening to Data Changes . Alternatively, you can use the custom editor as described in Concepts: Editors and Renders and the next section.

+2
source

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.

+1
source

All Articles