I'm using two JTextField
in Java Swing form. Now I enter the values in JTextField1
. Next if I press ENTER KEY means the cursor move to JTextField2
. How to do this?
Add an ActionListener
to the first text field. In the ActionEvent
you can get the source object, cast it to a JTextField
and then invoke the transferFocus()
method.
Use actionListener
for the textField
.
Code snippet:
textField1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
textField1.transferFocus();
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.