protected final String getValueString() { if (inputField.isEditValid()) try { inputField.commitEdit(); } catch (Exception e) { } return inputField.getText(); }
// Override to check whether the edit is valid, // setting the value if it is and complaining if // it isn't. If it's OK for the editor to go // away, we need to invoke the superclass's version // of this method so that everything gets cleaned up. @Override public boolean stopCellEditing() { JFormattedTextField ftf1 = (JFormattedTextField) getComponent(); if (ftf1.isEditValid()) { try { ftf1.commitEdit(); } catch (java.text.ParseException exc) { } } else { // text is invalid if (!userSaysRevert()) { // user wants to edit return false; // don't let the editor go away } } return super.stopCellEditing(); }
@Override public boolean stopCellEditing() { JFormattedTextField ftf = (JFormattedTextField) getComponent(); if (ftf.isEditValid()) { try { ftf.commitEdit(); } catch (java.text.ParseException exc) { // nothing to do } } else { if (!askEditOrRevert(ftf, null)) { return false; } else { ftf.setValue(ftf.getValue()); } } return super.stopCellEditing(); }
// 当输入组件失去焦点时,该方法被触发 public boolean verify(JComponent component) { JFormattedTextField field = (JFormattedTextField) component; // 返回用户输入是否有效 return field.isEditValid(); }