Here you can find the source of addNewFocusListenerForTextField(final JTextField textField, final Runnable r)
public static void addNewFocusListenerForTextField(final JTextField textField, final Runnable r)
//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(); } }); } }