currently I use DocumentListener and when I enter "11111"
I get 5 events.
I want 1 event when user exits the field.
When an enter key is pressed in a JTextField, an ActionEvent is generated. In order to handle such event, ActionListener interface should be implemented.
If focus is on a JTextField and enter is pressed, the text field fires an ActionEvent.
The main difference between JTextField and JTextArea in Java is that a JTextField allows entering a single line of text in a GUI application while the JTextArea allows entering multiple lines of text in a GUI application.
Use a focus listener on the textfield itself.
field.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent e) {
System.out.println("User entered " + field.getText());
}
});
What you need is a FocusListener.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With