I'm really surprised this is not in the documentation or at least 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
:
/**
* 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?
尝试这种方式:
field.setInputVerifier(null);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.