开发者

Cancel a Keypress Event in GWT

I want to cancel a keypress event for a long textbox so that the character newly pressed by the user is not entered in the textbox

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


If your longBox_1 is a private member of your class, or a final var, the code to cancel the event is :

longBox_1.cancelKey();

Otherwise you can cast the source of the event, if you are sure it correspond to the TextBox :

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

Here is the doc for 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜