Share this page 

Make the ENTER key act like the TAB keyTag(s): AWT


First create a TextField that listen to the Enter and react like a Tab key [JDK11]
import java.awt.*;
import java.awt.event.*;

public class MyTextField extends TextField {
 MyTextField(int len) {
  super(len);
  addKeyListener(new KeyAdapter() {
   public void keyPressed(KeyEvent evt) {
    int key = evt.getKeyCode();
    if (key == KeyEvent.VK_ENTER)
     transferFocus();}});
  }
}
to use it, try something like this
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

 public class TestEnterAsTab extends Applet {
   MyTextField t1, t2;
   public void init(){
     MyTextField t1 = new MyTextField(10);
     MyTextField t2 = new MyTextField(10);
     add(t1);add(t2);
     }
}