Java Swing Focus addDefaultFocus(Window window, final JComponent component)

Here you can find the source of addDefaultFocus(Window window, final JComponent component)

Description

add Default Focus

License

Open Source License

Declaration

public static void addDefaultFocus(Window window,
            final JComponent component) 

Method Source Code

//package com.java2s;

import java.awt.Window;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JComponent;

public class Main {
    public static void addDefaultFocus(Window window,
            final JComponent component) {
        window.addWindowFocusListener(new WindowAdapter() {

            /*//from   w  w  w . jav  a 2  s. c o  m
             * (non-Javadoc)
             * 
             * @see
             * java.awt.event.WindowAdapter#windowGainedFocus(java.awt.event
             * .WindowEvent)
             */
            @Override
            public void windowGainedFocus(WindowEvent e) {
                component.requestFocusInWindow();
            }
        });
    }
}

Related

  1. adjustFocus(JComponent c)
  2. centreInFocusedWindow(Window window, int xOffset, int yOffset)
  3. checkComponentsFocusable(final Component _rootComponent)
  4. clearAWTFocus(Robot robot)