本文介绍了JavaFX中的键绑定2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在JFX 2中使用KeyBindings?我需要从carrige重新分配Enter键返回到我自己的功能,并且对于carrige返回分配CTRL + ENTER
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();
}
}
});
推荐答案
如果要防止事件的默认行为,过滤,您需要而不仅仅是 KeyEvent.KEY_PRESSED
并使用它们。
There are numerous kinds of KeyEvents, you may want to filter on KeyEvent.ANY instead of just KeyEvent.KEY_PRESSED
and consume them all.
这篇关于JavaFX中的键绑定2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!