e954. preventing invalid values in a cell in a jtable component.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 20 行

TXT
20
字号
This 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();
        }
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?