JavaFX KeyEvent.getText() returns empty?

╄→гoц情女王★ 提交于 2019-12-13 16:25:47

问题


According to the JavaDoc for KeyEvent's getText() method, it returns

A String describing the key code, such as "HOME", "F1" or "A", for key pressed and key released events. For key typed events, text is always the empty string.

However, when I try printing getText(), it works as expected for printable characters, but not for other keys. "a" and "A" are the results for pressing the a and Shift-A keys, but pressing the Home, F1, or arrow keys results in "". Similarly, it registers the pressing of the Shift key before the A key when I press Shift-A, but the getText() for Shift is "".

Strangely enough, pressing Ctrl + some key produces a non-printable control key.

Is this a bug, or at least a mismatch between the docs and the real behavior? I am using ScalaFX, so I suppose there could be a problem in the Scala interface, but I'm actually using the javafx.scene.input.KeyEvent and javafx.event.EventHandler classes, not their Scala wrappers, so I doubt that's the problem.

来源:https://stackoverflow.com/questions/22839896/javafx-keyevent-gettext-returns-empty

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