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

[macosx] getSize() of JDialog returns wrong value

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_152-ea"
      Java(TM) SE Runtime Environment (build 1.8.0_152-ea-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 25.152-b05, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

      macOS Sierra 10.12.6 (16G29)

      A DESCRIPTION OF THE PROBLEM :
      After changing the size of a JDialog, the size returned by calling getSize() is incorrect for a few milliseconds.

      The first few milliseconds return the correct value
      The for the next few milliseconds (e.g. 15ms) an incorrect (old?) value is returned
      After that, the correct value is again returned.

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case and see if there is output on System.out saying:
      test failed on iteration xxx

      This means that getSize() returned a different size than was set using setSize()


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      getSize() returns the size that was last set using setSize()
      ACTUAL -
      getSize() returns a different size than was last set using setSize()

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Dimension;

      import javax.swing.JDialog;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      public class ResizeDialogTest {
      public static void main(String[] args) {
      SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
      test();
      }
      });
      }

      private static void test() {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.pack();
      frame.setSize(400, 400);
      frame.setVisible(true);

      JDialog dialog = new JDialog(frame, "Modal Dialog", true);
      dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      dialog.pack();
      dialog.setSize(200, 100);
      dialog.setSize(200, 200);

      // Keep asking the size and see if it stays correct.
      for (int i = 0; i < 100; ++i) {
      Dimension size = dialog.getSize();

      if (size.height != 200) {
      System.out.println("test failed on iteration " + i);
      }

      try {
      Thread.sleep(1);
      } catch (InterruptedException e) {
      e.printStackTrace();
      }
      }

      dialog.setVisible(true);
      }
      }

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

        1. ResizeDialogTest.java
          1 kB
        2. ResizeDialogTest.java
          1 kB
        3. win-mac.png
          win-mac.png
          22 kB
        4. win-mac.png
          22 kB

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: