Java JFrame toFront(final JFrame window)

Here you can find the source of toFront(final JFrame window)

Description

Bring a window to the front

License

Open Source License

Parameter

Parameter Description
window the window to bring to the front

Declaration

public static void toFront(final JFrame window) 

Method Source Code


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

import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Main {
    /**//www  .j a  va  2s  .  co m
     * Bring a window to the front
     * @param window the window to bring to the front
     */
    public static void toFront(final JFrame window) {
        WindowFocusListener listener = new WindowFocusListener() {

            public void windowGainedFocus(WindowEvent e) {
                window.setAlwaysOnTop(true);
            }

            public void windowLostFocus(WindowEvent e) {
                window.setAlwaysOnTop(false);
                window.removeWindowFocusListener(this);
            }
        };
        window.addWindowFocusListener(listener);
        window.toFront();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                window.requestFocus();
            }
        });
    }
}

Related

  1. smartSetBounds(JFrame frame)
  2. staggerOpenedFrames(List frames)
  3. storePrefsFrame(Preferences node, JFrame frame)
  4. tellUserToChoose(JFrame jFrame)
  5. terminarPrograma(JFrame f)
  6. toFront(JFrame frame)
  7. toFrontHack(JFrame theParent, JFrame theFrame)
  8. toggleFrame(JFrame frame)
  9. toggleOsXFullScreen(JFrame frame)