Re: Why JWindow can not catch the KEY Type event?
JTL.zheng wrote:
..
JWindow window= new JWindow();
Somebody asked recently, what good
was a JWiindow, over an undecorated JFrame,
and apparently, *not* for..
window.addKeyListener(new KeyListener() {
..KeyListener! I expect it has something to do with
being keyboard focusable - put a text field in it, and
that may change it.
OTOH..
What should I do if I want to catch the KEY type event in JWindow?
What about something that 'looks just like it'?
<sscce>
import javax.swing.JFrame;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
public class TestFocus {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setUndecorated(true);
f.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
System.out.println((int) e.getKeyChar());
}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent e) {}
});
System.out.println( "f.isFocusable() " + f.isFocusable() );
f.setSize(200,200);
f.setVisible(true);
}
}
</sscce>
HTH
--
Andrew Thompson
http://www.athompson.info/andrew/
Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200705/1