Reputation: 1336
I would like to cancel a particular keypress event in a RichTextBox.
Here it is described how to do it in a regular TextBox, but it doesn't work in a RichTextArea because it doesn't have the cancelKey() method.
Here's my code:
RichTextArea richTextArea = new RichTextArea();
...
richTextArea.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent arg0) {
if (arg0.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
// Here is where I would like to prevent the ENTER key from going to the richTextBox
}
}
});
Upvotes: 0
Views: 933
Reputation: 121998
Try this working fine for me ...
RichTextArea richTextArea = new RichTextArea();
richTextArea.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent arg0) {
if (arg0.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
arg0.getNativeEvent().preventDefault();
}
}
});
Upvotes: 2