You can override the onPreviewNativeEvent()
method of the DialogBox
class:
public void onModuleLoad() {
ExtendedDialogBox dialog = new ExtendedDialogBox();
dialog.add(new Label("some content"));
dialog.show();
}
private class ExtendedDialogBox extends DialogBox {
@Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
super.onPreviewNativeEvent(event);
switch (event.getTypeInt()) {
case Event.ONKEYDOWN:
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) {
hide();
}
break;
}
}
}
@Override
public boolean onKeyDownPreview(char key, int modifiers) {
switch (key) {
case KeyCodes.KEY_ESCAPE:
hide();
break;
}
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With