![]() |
The Java Developers Almanac 1.4 |
|
e954. Preventing Invalid Values in a Cell in a JTable ComponentThis example demonstrates how to modify a custom table cell editor to prevent invalid values from being saved. See e953 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 e953 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();
}
}
e955. Setting the Activation Click Count for a Table Cell Editor in a JTable Component e956. Programmatically Starting and Stopping Cell Editing in a JTable Component e957. Creating a Text Field That Mirrors the Value in the Anchor Cell in a JTable Component e958. Disabling User Edits in a JTable Component e959. Using a JComboBox in a Cell in a JTable Component e960. Using a List JSpinner as a Cell Editor in a JTable Component
© 2002 Addison-Wesley. |