Can I catch the event of exiting a JTextField
currently I use DocumentListener and when I enter "11111"
I get 5 events.I want 1 event w开发者_运维知识库hen user exits the field.
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.
currently I use DocumentListener and when I enter "11111" I get 5 events.
Sounds like you are trying to validate the data in the text field when you lose focus.
If this is the case then use an InputVerifier. The API has a working example.
精彩评论