开发者

Can I catch the event of exiting a JTextField

开发者 https://www.devze.com 2023-03-07 10:11 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号