开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜