Adding KeyListener to a JWindow not getting any key events
Posted
by Untitled
on Stack Overflow
See other posts from Stack Overflow
or by Untitled
Published on 2010-06-10T23:37:23Z
Indexed on
2010/06/10
23:43 UTC
Read the original article
Hit count: 332
Hello everyone,
In Java, I am adding a KeyListener to a JWindow, but it is not getting any key events. If I used the same code but extend a JFrame instead, then everything works fine.
public class MyWindow extends JWindow {
...
...
private void initComponents() {
...
...
addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
System.out.println("KEY PRESSED: " + e.getKeyCode());
}
public void keyReleased(KeyEvent e) {
System.out.println("KEY RELEASED: " + e.getKeyCode());
}
public void keyTyped(KeyEvent e) {
System.out.println("KEY TYPED: " + e.getKeyCode());
}
});
}
}
Anyone know how can I solve this by using a JWindow?
Please note that I am using Linux, so I am not sure if it is something to do with the platform.
Thanks
© Stack Overflow or respective owner