gpt4 book ai didi

java - 从 JTextField 中删除 InputVerifier

转载 作者:行者123 更新时间:2023-12-02 04:56:05 25 4
gpt4 key购买 nike

我真的很惊讶this is not in the documentationat least google .

我有一个类可能需要删除 validator 或将其替换为另一个 validator 。特别是,这些方法是在接口(interface)中定义的:

  /**
* 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 取消设置输入 validator ?

最佳答案

试试这个方法:

field.setInputVerifier(null);

关于java - 从 JTextField 中删除 InputVerifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28760881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com