Java JTextComponent Select addSelectAllTextOnFocus(final JTextComponent component)

Here you can find the source of addSelectAllTextOnFocus(final JTextComponent component)

Description

add Select All Text On Focus

License

Open Source License

Declaration

public static void addSelectAllTextOnFocus(final JTextComponent component) 

Method Source Code

//package com.java2s;
/*//from  ww w  .  java2 s  .  c  o  m
 * Copyright (c) 2007, Lan Boon Ping. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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

import javax.swing.text.JTextComponent;

public class Main {
    public static void addSelectAllTextOnFocus(final JTextComponent component) {
        component.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent e) {
                component.selectAll();
            }
        });
    }
}

Related

  1. focusSelect(final JTextComponent tf)
  2. isSelectionUpperCase(JTextComponent textPane)
  3. replaceSelectionAndSelect(JTextComponent component, String text)
  4. selectAll(final JTextComponent textComponent)