Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.JTextField;

import javax.swing.SwingUtilities;

public class Main {
    /**
     * Same as {@link #requestFocus(Component)} but also selects all text in the text-field.
     */
    public static void requestFocusSelectAll(final JTextField c) {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                c.requestFocusInWindow();
                int l = c.getDocument().getLength();
                if (l > 0) {
                    c.setSelectionStart(0);
                    c.setSelectionEnd(l);
                }
            }
        });
    }
}