本文整理汇总了Java中javax.swing.text.MaskFormatter.setValueClass方法的典型用法代码示例。如果您正苦于以下问题:Java MaskFormatter.setValueClass方法的具体用法?Java MaskFormatter.setValueClass怎么用?Java MaskFormatter.setValueClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.MaskFormatter
的用法示例。
在下文中一共展示了MaskFormatter.setValueClass方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateUsPhoneNumber
import javax.swing.text.MaskFormatter; //导入方法依赖的package包/类
/**
* 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";
}
示例2: ScheduleDurationField
import javax.swing.text.MaskFormatter; //导入方法依赖的package包/类
/**
* @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);
}
示例3: ScheduleTimeField
import javax.swing.text.MaskFormatter; //导入方法依赖的package包/类
/**
* @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);
}