コード例 #1
0
  /** DOCUMENT ME! */
  private void spinnerChanged() {
    if (LOG.isDebugEnabled()) {
      LOG.debug("spinner changed", new CurrentStackTrace());
    }

    try {
      lockSpinnerChange(true);

      final AbstractFormatter formatter =
          ((JSpinner.DefaultEditor) getValueSpinner().getEditor()).getTextField().getFormatter();
      final String text =
          ((JSpinner.DefaultEditor) getValueSpinner().getEditor()).getTextField().getText();
      if (!text.isEmpty()) {
        try {
          setPointValue((Double) formatter.stringToValue(text));
        } catch (ParseException ex) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("error parsing spinner", ex);
          }
        }
      }
    } finally {
      lockSpinnerChange(false);
    }
  }
コード例 #2
0
 /*
  *  (non-Javadoc)
  * @see javax.swing.InputVerifier#verify(javax.swing.JComponent)
  */
 public boolean verify(JComponent input) {
   if (input instanceof YFormattedTextField) {
     YFormattedTextField field = (YFormattedTextField) input;
     AbstractFormatter formatter = field.getFormatter();
     if (formatter != null) {
       String text = field.getText();
       if (!text.trim().equals("")) {
         try {
           formatter.stringToValue(text);
         } catch (ParseException pe) {
           field.setInvalidLayout();
           return false;
         }
       }
     }
     field.setValidLayout();
   }
   return true;
 }