Java JTextField Focus addNewFocusListenerForTextField(final JTextField textField, final Runnable r)

Here you can find the source of addNewFocusListenerForTextField(final JTextField textField, final Runnable r)

Description

add New Focus Listener For Text Field

License

Open Source License

Declaration

public static void addNewFocusListenerForTextField(final JTextField textField, final Runnable r) 

Method Source Code

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

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JTextField;

public class Main {
    public static void addNewFocusListenerForTextField(final JTextField textField, final Runnable r) {
        textField.addFocusListener(new FocusListener() {

            @Override/* w w w .  j a  va 2 s .c  o  m*/
            public void focusLost(final FocusEvent arg0) {
                r.run();
            }

            @Override
            public void focusGained(final FocusEvent arg0) {
                textField.selectAll();
            }
        });
    }
}

Related

  1. _createJTextField(String name, FocusListener fl)
  2. addListenerToCommitOnFocusLost(final JTextField field)
  3. attachListenerOnLabelClickFocusTextElement(JLabel label, final JTextField textField)
  4. clearOnFocus(final JTextField jtf, final String onlyInText)
  5. configureFocusActionKeys(JTextField textField, boolean primary)
  6. makeSureUserGetsFocus(final JTextField field)