import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import javax.swing.JTextField; class MyTextField extends JTextField { MyTextField(int len) { super(len); addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { int key = evt.getKeyCode(); if (key == KeyEvent.VK_ENTER) transferFocus(); } }); } }