TextArea ignore KeyEvent in JavaFX

£可爱£侵袭症+ 提交于 2019-12-11 14:05:19

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!