Here you can find the source of toFront(final JFrame window)
Parameter | Description |
---|---|
window | the window to bring to the front |
public static void toFront(final JFrame window)
//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(); } }); } }