jtextfield keyevent handling issue

Posted by vamsi on Stack Overflow See other posts from Stack Overflow or by vamsi
Published on 2010-03-04T05:03:26Z Indexed on 2010/04/12 10:03 UTC
Read the original article Hit count: 296

Filed under:

doesn't .getKeyCode( ) return the key's int value? Because i have set my jtextfield to listen to keylistener, and in the keytyped method, i check what key has been pressed. Here's a snippet of my code:

JTextField jtf = new JTextField( ); jtf.addKeyListener( this ); . . . public void keyTyped( KeyEvent e ) { if( e.getKeyCode( ) == KeyEvent.VK_ENTER ) System.out.println( "pressed enter" ); }

but everytime i type enter in the jtextfield, nothing happens, ie nothing prints.

© Stack Overflow or respective owner

Related posts about jtextfield