Joe
Joe

Reputation: 795

How do I add a Keyboard Short to a GWT button in our web app?

I am new to GWT and would like to add a simple keyboard shortcut to a 'Yes' button in a dialog popup in our application? I have looked around and can not seem to find clear way of adding one.

thank you for any help.

Upvotes: 2

Views: 413

Answers (1)

Andrei Volgin
Andrei Volgin

Reputation: 41089

Override onPreviewNativeEvent method in your dialog:

@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
    super.onPreviewNativeEvent(event);
    if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
        hide();
    }
    if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
        // submit(); - or whatever you need to do here
    }
}

Upvotes: 4

Related Questions