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

Using JFrame.setDefaultLookAndFeelDecorated(true) causes the frame to flicker

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.2
    • client-libs
    • x86
    • windows_xp



      Name: gm110360 Date: 05/03/2004


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Windows 98 [Version 4.10.1998]


      A DESCRIPTION OF THE PROBLEM :
      Resizing a frame causes rapid flickering when JFrame.setDefaultLookAndFeelDecorated(true) is used.

      This thread from the Swing forum has input from other users using different OSes and JDK's.
      http://forum.java.sun.com/thread.jsp?forum=57&thread=503874


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run the program
      2) Drag the frame border to make it wider

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Frame should resize without flickering.
      ACTUAL -
      Contents of the frame flicker while frame is being resized.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class BugDecorated extends JFrame
      {
          public BugDecorated()
          {
              JTable table = new JTable(5, 5);
              table.setPreferredScrollableViewportSize( table.getPreferredSize() );
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
          }

          public static void main(String[] args)
          {
              // Comment the following line and it resizes without flickering
              JFrame.setDefaultLookAndFeelDecorated(true);
      //
              BugDecorated frame = new BugDecorated();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Adding a ComponentListener to the frame and setting a System property as shown below seems to work reasonably well.

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class BugDecorated extends JFrame
      {
          public BugDecorated()
          {
              JTable table = new JTable(5, 5);
              table.setPreferredScrollableViewportSize( table.getPreferredSize() );
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );

      addComponentListener(new ComponentAdapter()
      {
      public void componentResized(ComponentEvent e)
      {
      getRootPane().repaint();
      }
      });

          }

          public static void main(String[] args)
          {
              // Comment the following line and it resizes without flickering
              JFrame.setDefaultLookAndFeelDecorated(true);
              System.setProperty("sun.awt.noerasebackground", "true");
      //
              BugDecorated frame = new BugDecorated();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
          }
      }
      (Incident Review ID: 244160)
      ======================================================================

            dav Andrei Dmitriev (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: