title: Flashing JFrame
body: <p>I would like to create a JFrame with two specifal features:</p>
  
  <ol>
  <li>JFrame should not grab focus while maximized from minimized state.</li>
  <li>When a JFrame created or became maximized from minimized state, it should flash in the Windows bar until a user will grant a focus to it. (like as in ICQ clients <img src="https://i.stack.imgur.com/dKwJV.jpg" alt="alt text">).</li>
  </ol>
  
  <p>Does anybody know how the second requirement can be implemented?</p>
  
  <p>Little self-explained example:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.event.*;
  import java.awt.*;
  
  public class JFrameTest {
      private static JFrame childFrame;
      public static Container getParentContentPane() {
          JPanel panel = new JPanel();
          JButton button = new JButton("Create\\Restore child frame");
          button.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e) {
                  createOrRestoreChildFrame();
              }
          });
          panel.add(button);
          return panel;
      }
  
      private static void createOrRestoreChildFrame() {
          if (childFrame == null) {
              childFrame = new JFrame("Child Frame");
              childFrame.setLocation(200, 200);
              childFrame.add(new JLabel("Child Frame"));
              childFrame.pack();
              setChildFrameVisible();
          } else {
              setChildFrameVisible();
          }
      }
  
      private static void setChildFrameVisible() {
          childFrame.setFocusableWindowState(false);
          childFrame.setVisible(true);
          flashInWindowsBar(childFrame);
          childFrame.toFront();
          childFrame.setFocusableWindowState(true);
      }
  
      /**
       * Should Make child frame flash in Windows bar.
       * Currently, it does not work for me.
       * Could anybody help me to fix this please? ) 
       */
      private static void flashInWindowsBar(JFrame childFrame) {
          childFrame.setState(JFrame.ICONIFIED);
          childFrame.toFront();
      }
  
      private static void createAndShowGUI() {
          JFrame parentFrame = new JFrame("JFrame Demo");
          parentFrame.setLocation(100, 100);
          parentFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          parentFrame.setContentPane(getParentContentPane());
          parentFrame.pack();
          parentFrame.setVisible(true);
      }
  
      public static void main(String[] args) {
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  createAndShowGUI();
              }
          });
      }
  }
  </code></pre>
  
  <p>Thanks!</p>