Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8041467

Frames flicker when

XMLWordPrintable

      FULL PRODUCT VERSION :
      1.7.0_25

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 7 Enterprise Version 6.1 (Build 7601: Service Pack 1)

      A DESCRIPTION OF THE PROBLEM :
      I use an off screen JFrame to give a task bar entry for a JDialog in one use case. I use a 'windowActivated' listener to determine when to pull my JDialog into focus.

      Starting in Java 7, this workflow leads to an infinately flicker between the two Windows, when auto-focus is set to 'true.'






      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run the attached sample code.

      the sample code creates a frame that brings a dialog into focus.

      2. From the Window's task bar, click on the frame.

      Focus will repeatedly flicker between the dialog if autoFocus is 'true'.

      Monitor the console and note how the toFront method is repeatedly called. Note that the sample code has a toFront override with a print statement for tracking purposes.

      The flicker can go on infinitely, in which case clicking somewhere will break the cycle.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect the frame to focus once.
      ACTUAL -
      The frame repeatedly flickers until something is clicked.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dialog;
      import java.awt.event.WindowAdapter;
      import java.awt.event.WindowEvent;
      import javax.swing.JDialog;
      import javax.swing.JFrame;
      import javax.swing.JLabel;

      public class TestDialogParent {
          public static void main(String[] args) {

              final JDialog dialog = new JDialog(){
                  @Override
                  public void toFront() {
                      super.toFront();
                      System.out.println("The JDialog's toFront called");
                  }
              };

              dialog.add(new JLabel("Dialog"));

              dialog.setLocation(200,0);
              dialog.setSize(200,200);
              dialog.setVisible(true);

              DialogParent dialogParent = new DialogParent();
              dialogParent.setVisible(true);
              dialogParent.pack();
              dialogParent.add(new JLabel("JFrame"));
              dialogParent.attachDialog(dialog);
          }


          private static class DialogParent extends JFrame{
              public void attachDialog(Dialog dialog)
              {
                  addWindowListener(new FrameListener(dialog));
              }
          }


          private static class FrameListener extends WindowAdapter
          {
              private final Dialog fDialog;

              private FrameListener(Dialog dialog) {
                  fDialog = dialog;
              }

              @Override
              public void windowActivated(WindowEvent e) {
                  if (fDialog.isVisible()){
                      fDialog.toFront();
                  }


              }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Set the dialog's auto-focus to 'false.'

            ant Anton Tarasov (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: