title: Bringing borderless swing window to front
body: <p>I have a swing program which creates a fullscreen borderless window -- I am running on Windows 7. I need the program to be able to focus and bring itself to the front. However, when I attempt to use the method found here, <a href="https://stackoverflow.com/questions/309023/howto-bring-a-java-window-to-the-front">How to bring a window to the front?</a>, instead of bringing the window to the front the window just flashes in the taskbar and does not accept input. Below I wrote a small program that demonstrates the issue:</p>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import javax.swing.JFrame;
  import javax.swing.SwingUtilities;
  import javax.swing.Timer;
  
  
  public class WindowTest extends JFrame{
  
  WindowTest(){
      setTitle("Window Test");
      setSize(600, 600);
      setLocationRelativeTo(null);
      setUndecorated(true);
      setExtendedState(JFrame.MAXIMIZED_BOTH);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
  
  public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
          public void run() {
              final WindowTest wt = new WindowTest();
              wt.setVisible(true);
  
              Timer t = new Timer(3000,new ActionListener(){
                  @Override
                  public void actionPerformed(ActionEvent arg0) {
                      java.awt.EventQueue.invokeLater(new Runnable() {
                          @Override
                          public void run() {
                              wt.toFront();
                              wt.repaint();
                          }
                      });             
                  }   
              });
  
              t.setRepeats(false);
              t.start();
  
              wt.addKeyListener(new KeyListener(){
                  @Override
                  public void keyPressed(KeyEvent arg0) {
                      if(arg0.getKeyCode() == KeyEvent.VK_ESCAPE){
                          wt.dispose();
                          System.exit(0);
                          return;
                      }
                  }
  
                  @Override
                  public void keyReleased(KeyEvent arg0) {
                      // TODO Auto-generated method stub
  
                  }
  
                  @Override
                  public void keyTyped(KeyEvent arg0) {
                      // TODO Auto-generated method stub
  
                  }   
              });
          }
      });
  
  }
  
   }
  </code></pre>
  
  <p>This will create a borderless, maximized window, and then three seconds later will attempt to bring it to the front. If you change to another window before that, the taskbar button will flash but the window will not be brought to the front.</p>