JAVA - Validation in JTable

I try to check cell in JTableas soon as the data is entered. I want to make sure that the correct code is entered in the code column. Can someone let me know how to do this, please?

+5
source share
1 answer

You must implement TableCellEditorand perform validation as part of the method stopCellEditing(). If validation fails, this method should return false. From Javadoc:

"Tells the editor to stop editing and accept some partially edited value as the value of the editor. The editor returns false if editing has not been stopped; this is useful for editors who check and cannot accept invalid entries ."

Take a look at the GenericEditor class defined in the JTableexample.

One more thing worth paying attention to: you can always build DefaultCellEditorwith JFormattedTextFieldas a parameter and add InputVerifierto the text box to prevent writing invalid data.

+4
source

All Articles