我正在尝试实现一个像这样的文本字段:
文本字段验证 http://imageshack.com/a/img537/8329/FSht8P.png
我的目标是确定 TextField 的文本是 aDouble
还是其他东西(然后它显示为红色)。我想使用ControlsFX来学习库而不是编辑 css,但效果不是很好,而且我迷失在 javadoc 中。有没有人有一个例子或可以帮助我改进我的代码?
这是我试图做的:
Validator<Double> checkTextField = new Validator<Double>() {
@Override
public ValidationResult apply(Control t, Double u) {
ValidationResult vd = new ValidationResult();
if(Double.valueOf(t.toString()) != null){
vd.addErrorIf(t, "false", false);
}
return vd;
}
};
ValidationSupport validationSupport = new ValidationSupport();
validationSupport.registerValidator(latitudeTextField, checkTextField/*Validator.createEmptyValidator("Text is required")*/);
ValidationDecoration iconDecorator = new GraphicValidationDecoration();
ValidationDecoration cssDecorator = new StyleClassValidationDecoration();
ValidationDecoration compoundDecorator = new CompoundValidationDecoration(cssDecorator, iconDecorator);
validationSupport.setValidationDecorator(compoundDecorator);