how to listen to ESC key for popup

588 views
Skip to first unread message

aragorn

unread,
Jan 15, 2009, 4:17:15 AM1/15/09
to Google Web Toolkit
My application displays a popup whenevr a particular button is
clicked. Now i can hide the popup whenever the user clicks the mouse
outside of it using the default popup-panel property provided by GWT.
Apart from that I also need to listen to keyboard so that if the user
hits ESC on the keyboard my popup should disappear from the screen.
Any idea how to implement in gwt?

Hasan Turksoy

unread,
Jan 15, 2009, 4:27:42 AM1/15/09
to Google-We...@googlegroups.com

you can override the PopupPanel#onKeydownPreview method like below;

    @Override
    public boolean onKeyDownPreview(char key, int modifiers) {
        // Use the popup's key preview hooks to close the dialog when either
        // enter or escape is pressed.
        switch (key) {
        case KeyboardListener.KEY_ENTER:
        case KeyboardListener.KEY_ESCAPE:
            hide();
            break;
        }

        return true;
    }


Hasan...
http://www.jroller.com/hasant

sagar

unread,
Jan 22, 2009, 11:40:12 PM1/22/09
to Google-We...@googlegroups.com
hey thanks Hasan
it works.
However it is working only for ESC and not for ENTER even though i have used the above lines in my code.

Hasan Turksoy

unread,
Jan 23, 2009, 2:21:16 AM1/23/09
to Google-We...@googlegroups.com

In general, this occurs when another widget other than dialog (which is listening Enter and Esc keys) has got the focus...
Reply all
Reply to author
Forward
0 new messages