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

Window frame flickers when displaying JPopup with focusable component

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Pro 22H2
      Java 21.0.2+12-LTS-58
      Java 11.0.8

      A DESCRIPTION OF THE PROBLEM :
      When showing a JPopup that has a focusable component ( ex: JTextField ) that renders partially outside the root JFrame, the frame will flash before displaying the popup. If the popup bounds are entirely within the frame, no flashing occurs.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile and run the attached example
      2. Click within JFrame on JLabel "header". Popup will render where mouse was clicked. Default sizes will be such that part of popup will be outside the frame and frame will "flash."
      3. Increase frame size and click again. If popup is contained in frame, frame will not flash
      4. Set textField.setFocusable(false) and frame will not flash regardless of where it is displayed.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Popup should display without frame flashing
      ACTUAL -
      Frame flashes when popup is displayed

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;

      public class PopupTesting
      {
          public static void main( String[] args )
          {
              SwingUtilities.invokeLater( () ->
              {

                  JPopupMenu popupMenu = new JPopupMenu();

                  for( int i = 0; i < 10; i++ )
                  {
                      popupMenu.add( new JCheckBoxMenuItem( "A Menu " + i ) );
                  }

                  JTextField textField = new JTextField( "" );
                  popupMenu.add( textField );

                  textField.setFocusable( true);

                  JFrame frame = new JFrame( "Popup Testing" );
                  frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
                  JLabel header = new JLabel( "Header" );
                  header.setPreferredSize( new Dimension( 200, 100 ) );

                  header.addMouseListener( new MouseAdapter()
                  {
                      @Override
                      public void mouseClicked( MouseEvent e )
                      {
                          popupMenu.show( header, e.getX(), e.getY() );
                      }
                  } );

                  JPanel panel = new JPanel(new BorderLayout());
                  panel.add( header );

                  frame.setContentPane( panel );

                  frame.pack();
                  frame.setVisible( true );
              } );
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. flashing.mp4
          698 kB
        2. PopupTesting.java
          1 kB
        3. WINDOWS10.mp4
          293 kB

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: