Java Code Examples for javax.swing.text.MaskFormatter.setValueClass()

The following are Jave code examples for showing how to use setValueClass() of the javax.swing.text.MaskFormatter class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: invesdwin-nowicket   File: FormInput.java   Source Code and License Vote up 6 votes
/**
 * Instead of using the MaskConverter in the Page, we just validate the value here with a custom validator.
 */
public String validateUsPhoneNumber(final String newValue) {
    try {
        final MaskFormatter maskFormatter = new MaskFormatter("(###) ###-####");
        maskFormatter.setValueClass(String.class);
        maskFormatter.setAllowsInvalid(true);
        maskFormatter.setValueContainsLiteralCharacters(true);
        final Object obj = maskFormatter.stringToValue(newValue);
        if (obj != null) {
            return null;
        }
    } catch (final ParseException e) {
        //ignore
    }
    //so we can provide a different message than "is not a valid string"
    return "does not match the mask";
}
 
Example 2
Project: fll-sw   File: ScheduleDurationField.java   Source Code and License Vote up 6 votes
/**
 * @param value the duration to use for the initial value, may not be null
 */
public ScheduleDurationField(final Duration value) {
  setInputVerifier(new TimeVerifier());

  try {
    final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
    mf.setPlaceholderCharacter('_');
    mf.setValueClass(String.class);
    final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
    setFormatterFactory(dff);
  } catch (final ParseException pe) {
    throw new FLLInternalException("Invalid format for MaskFormatter", pe);
  }

  setDuration(value);
}
 
Example 3
Project: fll-sw   File: ScheduleTimeField.java   Source Code and License Vote up 5 votes
/**
 * @param value the initial value for the widget
 */
public ScheduleTimeField(final LocalTime value) {
  try {
    final MaskFormatter mf = new MaskFormatter(MASKFORMAT);
    mf.setPlaceholderCharacter('_');
    mf.setValueClass(String.class);
    final DefaultFormatterFactory dff = new DefaultFormatterFactory(mf);
    setFormatterFactory(dff);
  } catch (final ParseException pe) {
    throw new FLLInternalException("Invalid format for MaskFormatter", pe);
  }

  setTime(value);
}