Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTextField FocusListener not behaving as expected?

843806Oct 8 2007 — edited Oct 9 2007
I'm adding the following code to a JTextField
        FocusListener listener = new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {
                // do nothing
            }

            @Override
            public void focusLost(FocusEvent e) {
                valueChanged();
            }
        };
        field.addFocusListener( listener);
It works great when I click around from one field to another, but when I click on a save button, the event is not called. This is a plugin to a project, so I do not have access add a listener to the button itself.

But shouldn't clicking on the button call the focusLost event?

I quickly hacked together what I thought would be a temporary solution by injecting code, but no dice.
      JTextField textField = new JTextField();
        textField.setVisible(true);
        textField.setFocusable(true);
        textField.requestFocusInWindow();
        textField.grabFocus();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 6 2007
Added on Oct 8 2007
7 comments
417 views