KeyListener not working

前端 未结 1 1281
礼貌的吻别
礼貌的吻别 2020-12-04 03:33

For some reason, my KeyListener just isn\'t responding to KeyPressed events.

If it matters, I\'m on Ubuntu 12.04. It should be printing \"Key Pressed\" whenever a k

相关标签:
1条回答
  • 2020-12-04 03:52
    • Call super.paintComponent (not related to you question, but will solve some issues later on)
    • Make the component "focusable" - Component#setFocusable
    • Use key bindings over KeyListener
    • Use Component#requestFocusInWindow over Component#requestFocus...

    From the Java Docs

    Because the focus behavior of this method is platform-dependent, developers are strongly encouraged to use requestFocusInWindow when possible

    0 讨论(0)
提交回复
热议问题