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

JFrame window size is not consistent on Ubuntu

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_31"
      Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
      Java HotSpot(TM) Server VM (build 25.31-b07, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux art-Inspiron-N5010 3.13.0-32-generic #57-Ubuntu SMP
      Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      On Ubuntu Linux, there are unexpected variations in the height of JFrames that have their dimension explicitly set via the setSize method. The problem is most obvious when rendering two JFrames at the same time that are supposed to have the same dimensions -- over 50% of the time one of the JFrames is taller than the other.

      This issue has thus far only been reproduced on Ubuntu. This problem does NOT exist when running the same code on Windows 7.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See the attached code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      JFrames that are identical and are set to the same size should be the same size.
      ACTUAL -
      Two otherwise identical JFrames that are set to the same size are sometimes displayed with different heights. When the frames are different heights the 1st frame made visible is always the taller of the two frames.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      // When running this app on Windows the frames are (as expected) the same
      // size, but when run on Ubuntu Linux roughly 70% of the time the 2 frames
      // have different heights.
      //
      // On Ubuntu, when the frames are different heights the 1st frame made visible
      // is always the taller of the two frames. Thus in the example as written, if
      // the frames are are not the same size then f1 will always be taller than f2,
      // but if the example is changed to make f2 visible before f1, then f2 will be
      // taller than f1.
      //
      // The inconsistent behaviour hinted at a possible race condition when rendering
      // the two frames, so the test was modified to add a timer to delay the rendering
      // of the 2nd frame, as shown below in test2. However, if anything, this seemed
      // to make it even less likely that the two frames would be the same size.

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JFrame;
      import javax.swing.Timer;

      public class JFrameSizingErrorExample implements Runnable {
          public static void main(String[] args) {
              java.awt.EventQueue.invokeLater(new JFrameSizingErrorExample());
          }

          @Override public void run() {
              final JFrame f1 = new MyFrame(1, 32, 32);
              final JFrame f2 = new MyFrame(2, 600, 32);
              f1.setVisible(true);
              f2.setVisible(true);
          }
          
          class MyFrame extends JFrame {
              public MyFrame(int frameNum, int x, int y) {
                  setTitle("Frame-" + frameNum);
                  setLocation(x, y);
                  setSize(300, 200);
                  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              }
          }
          
          void test2()
          {
              final JFrame f1 = new MyFrame(1, 32, 32);
              final JFrame f2 = new MyFrame(2, 600, 32);
              f1.setVisible(true);
              
              Timer timer = new Timer(1000 ,new ActionListener() {
                  public void actionPerformed(ActionEvent evt) {
                      f2.setVisible(true);
                  }
              });
              timer.setRepeats(false);
              timer.start();
          }
      }
      ---------- END SOURCE ----------

            ssadetsky Semyon Sadetsky (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: