Cannot listen to KeyEvent in JavaFX

ε祈祈猫儿з 提交于 2019-11-30 13:50:53
Alexander Kirov

One solution is to add an event listener to the scene. Because layouts don't have focus by default, so they don't respond on KeyEvents. KeyEvents are passed to the focused node first.

Another solution is to make your pane focusable:

root.setFocusTraversable(true)
Elmer Duron

((KeyEvent)t).getCharacter() instead use ((KeyEvent)e).getText()

also make sure you are importing the correct KeyEvent as in

import javafx.scene.input.KeyEvent;

rather than the KeyEvent from awt

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