Java JTextField Focus addListenerToCommitOnFocusLost(final JTextField field)

Here you can find the source of addListenerToCommitOnFocusLost(final JTextField field)

Description

Add Focus listener to text field to commit field whenever it loses focus.

License

Open Source License

Parameter

Parameter Description
field field to commit when losing focus

Declaration

public static void addListenerToCommitOnFocusLost(final JTextField field) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

import javax.swing.JTextField;

public class Main {
    /**/* w  w w  . j a v a2s.c om*/
     * Add Focus listener to text field to commit field whenever it loses focus.
     * @param field field to commit when losing focus
     */
    public static void addListenerToCommitOnFocusLost(final JTextField field) {
        field.addFocusListener(new FocusAdapter() {
            public void focusLost(FocusEvent evt) {
                field.postActionEvent();
            }
        });
    }
}

Related

  1. _createJTextField(String name, FocusListener fl)
  2. addNewFocusListenerForTextField(final JTextField textField, final Runnable r)
  3. attachListenerOnLabelClickFocusTextElement(JLabel label, final JTextField textField)
  4. clearOnFocus(final JTextField jtf, final String onlyInText)
  5. configureFocusActionKeys(JTextField textField, boolean primary)