How to use KeyBindings in JFX 2? I need to reassign Enter key from carrige returning to my own function, and for carrige returning assign CTRL+ENTER
I’ve tried this way, but still it makes a new line.
messageArea.addEventFilter(KeyEvent.KEY_PRESSED, new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent keyEvent) {
if (keyEvent.getCode() == KeyCode.ENTER) {
sendMessage();
}
}
});
If want to prevent the default behavior of event you are filtering, you need to consume it.
There are numerous kinds of KeyEvents, you may want to filter on KeyEvent.ANY instead of just
KeyEvent.KEY_PRESSEDand consume them all.