gpt4 book ai didi

java - 在 GWT 中取消按键事件

转载 作者:行者123 更新时间:2023-12-02 00:46:32 25 4
gpt4 key购买 nike

我想取消长文本框的按键事件,以便用户新按下的字符不会输入到文本框中

longBox_1.addKeyPressHandler(new KeyPressHandler(){
@Override
public void onKeyPress(KeyPressEvent event) {
String Valid="1234567890";
if (!Valid.contains(String.valueOf(event.getCharCode()))) {
// the code to cancel the event to be placed here
}
}
});

最佳答案

如果您的 longBox_1 是您的类的私有(private)成员或最终变量,则取消事件的代码是:

longBox_1.cancelKey();

否则,如果您确定事件源对应于 TextBox,则可以转换事件源:

((TextBox)event.getSource()).cancelKey();

这是 cancelKey 的文档:

If a keyboard event is currently being handled on this text box, calling this method will suppress it. This allows listeners to easily filter keyboard input

关于java - 在 GWT 中取消按键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4872009/

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