Manu
Manu

Reputation: 65

I want to listen to changes in JtextField

I really do not want to listen to DocumentListener. It generates too many events for me. I am interested in listening only when the focus moves away from this specific JtextField. Adding ActionListener will generate an event only when return key is pressed. I would like to get it when the user moves away with a tab key or by moving the mouse away. Is this possible? Thanks and Regards

Upvotes: 0

Views: 329

Answers (1)

Vinay
Vinay

Reputation: 6879

Use FocusListener. focusLost will help you when user moves to some other fields.

        JTextField jf = new JTextField();
        jf.addFocusListener(new FocusListener() {

            @Override
            public void focusLost(FocusEvent arg0) {
                // here you can have your code when user moves out
            }

            @Override
            public void focusGained(FocusEvent arg0) {
                // TODO Auto-generated method stub

            }
        } );

Upvotes: 1

Related Questions