Simple example:
Suppose you have two JTextField
s: textField
and textField1
textField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField1.requestFocusInWindow();
}
});
textField1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
textField.requestFocusInWindow();
}
});
Now when you hit Enter
when focused on the first JTextField
, the other one will be focused, and vice versa.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…