问题
Java,JavaFX As in tittle, how can i force TextArea to ignore KeyEvent,and make sth instead of this KeyEvent. I should rather say that I would like to overwrite method which append a character from KeyEvent.
Fo example: If i click 'k' on keyboard in the TextArea i would like it to be printed in console (not appended to TextArea)
回答1:
Friend, try this:
TextArea textArea = new TextArea();
textArea.addEventFilter(KeyEvent.KEY_TYPED, e -> {
if (e.getCharacter().equals("k")) {
e.consume();
}
});
or:
TextArea textArea = new TextArea();
textArea.setOnKeyTyped(e -> {
if (e.getCharacter().equals("k")) {
e.consume();
}
});
来源:https://stackoverflow.com/questions/47370439/textarea-ignore-keyevent-in-javafx