从 JTextField 中删除 InputVerifier
Remove InputVerifier from JTextField
我真的很惊讶this is not in the documentation or at least google。
我有一个 class 可能需要删除验证器或用另一个替换它。特别是在接口中定义了这些方法:
/**
* Add the verifier
*/
public void bind();
/**
* Remove the verifier from input
*/
public void unbind();
我可以实现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;
}
});
}
但是我如何取消设置来自 JTextField 的输入验证器?
试试这个方法:
field.setInputVerifier(null);
我真的很惊讶this is not in the documentation or at least google。
我有一个 class 可能需要删除验证器或用另一个替换它。特别是在接口中定义了这些方法:
/**
* Add the verifier
*/
public void bind();
/**
* Remove the verifier from input
*/
public void unbind();
我可以实现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;
}
});
}
但是我如何取消设置来自 JTextField 的输入验证器?
试试这个方法:
field.setInputVerifier(null);