How to bring a window to the front?

boutta picture boutta · Nov 21, 2008 · Viewed 150.3k times · Source

We have a Java application that needs to be brought to the foreground when a telecontrol mechanism activates something in the application.

In order to get this, we have realized in the called method of the class which represents the frame of our application (extension of a JFrame) following implementation:

setVisible(true);
toFront();

Under Windows XP, this works the first time it is called, on the second time only the tab in the taskbar flashes, the frame doesn't come to the front anymore. Same goes for Win2k. On Vista it seems to work fine.

Do you have any ideas?

Answer

 picture · Dec 22, 2008

A possible solution is:

java.awt.EventQueue.invokeLater(new Runnable() {
    @Override
    public void run() {
        myFrame.toFront();
        myFrame.repaint();
    }
});