[英]Remove InputVerifier from JTextField
I'm really surprised this is not in the documentation or at least google . 我真的很惊讶, 这不在文档中,或者至少 不在 google中 。
I have a class that is likely to need to remove the verifier or replace it with another one. 我有一类可能需要删除验证程序或将其替换为另一个的类。 In particular, these methods are defined in the interface:
特别是,这些方法在接口中定义:
/**
* Add the verifier
*/
public void bind();
/**
* Remove the verifier from input
*/
public void unbind();
I can implement bind
: 我可以实现
bind
:
/**
* Binds the events to the field using InputVerifier
*/
@Override
public void bind() {
//Internal verifier
final SettingsInputVerifier<T> verif = this.verifier;
//Event to be called if new value is valid
final ValueChanged<T> onchange = this.onchange;
//Only works when you leave the field
field.setInputVerifier(new InputVerifier() {
@Override
public boolean verify(JComponent in) {
//If verification fails, return false and ignore the value
if(!verif.verify(in))
return false;
//Sucessful verification means we get the value and update it
onchange.changed(verif.value(in));
return true;
}
});
}
But how can I unset input verifier from JTextField? 但是,如何从JTextField 取消输入验证程序?
尝试这种方式:
field.setInputVerifier(null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.