ENTER key used in JTextField java

I use two forms of JTextField in Java Swing. Now I enter the values โ€‹โ€‹in JTextField1 . Then, if I press ENTER , KEY means the cursor will move to JTextField2 . How to do it?

+4
source share
2 answers

Add an ActionListener to the first text box. In an ActionEvent you can get the source object, apply it to a JTextField and then call the transferFocus() method.

+11
source

Use actionListener for textField .

Code snippet:

 textField1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ textField1.transferFocus(); } }); 
+1
source

Source: https://habr.com/ru/post/1387321/


All Articles