Preventing Invalid Values in a Cell in a JTable Component

This example demonstrates how to modify a custom table cell editor to prevent invalid values from being saved. See Creating a Custom Table Cell Editor in a JTable Component for more information about table cell editors.
public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor { // See Creating a Custom Table Cell Editor in a JTable Component // for other methods that need to be implemented. // This method is called just before the cell value // is saved. If the value is not valid, false should be returned. public boolean stopCellEditing() { String s = (String)getCellEditorValue(); if (!isValid(s)) { // Should display an error message at this point return false; } return super.stopCellEditing(); } }

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.