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

[Linux] Dialog height switches between correct and too small when showing and hiding a Dialog repeatedly

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_141"
      Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 3.10.0-693.5.2.el7.x86_64 #1 SMP Fri Oct 20 20:32:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
      Linux 3.13.0-46-generic #79-Ubuntu SMP Tue Mar 10 20:06:50 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux



      A DESCRIPTION OF THE PROBLEM :
      When the same instance of a dialog is repeatedly shown and hidden, its height will switch between being as expected on the first, third, fifth etc. time it is shown, and being much too small the second, fourth, ... time it is shown.

      I could always reproduce the bug on Linux instances.

      I could NOT reproduce the bug on Microsoft Windows [Version 6.1.7601] and Java(TM) SE Runtime Environment (build 1.8.0_152-b16).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a dialog with a certain size.
      2. Show the dialog.
      3. Hide the dialog.
      4. Show the same dialog again.
      5. Repeat steps 3 and 4.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Every time the dialog is shown again after being hidden, it should have the same size/height as before.
      ACTUAL -
      The dialog size will be fine when first shown. The second time it is shown, its height will be much too small. For the following times it is shown, the dialog's height will consistently switch between being correct (third time, fifth time, ...) and being the same much too small size (fourth time, ...).

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestDialogSizingWhenHiddenAndShownAgain extends Application {

          public static void main(final String[] args) {
              launch(args);
          }

          @Override
          public void start(final Stage stage) {

              final Dialog<Void> testDialog = getTestDialog();

              final Button dialogButton = new Button("Open Dialog");
              dialogButton.setOnAction(evt -> testDialog.show());

              final Scene scene = new Scene(dialogButton, 300, 200);

              stage.setScene(scene);
              stage.show();
          }

          private static Dialog<Void> getTestDialog() {
              final Label dialogContent = new Label();
              dialogContent.setText("Dialog content");
              dialogContent.setPrefSize(300, 300);

              final Dialog<Void> testDialog = new Dialog<>();

              testDialog.getDialogPane().setContent(dialogContent);
              testDialog.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);

              // enableWorkaround(testDialog);

              return testDialog;
          }

          private static void enableWorkaround(final Dialog<?> dialog) {
              final String PREVIOUS_WIDTH = "PREVIOUS_WIDTH";
              final String PREVIOUS_HEIGHT = "PREVIOUS_HEIGHT";

              dialog.setOnShowing(evt -> {
                  dialog.getDialogPane().getProperties().put(PREVIOUS_WIDTH, dialog.getWidth());
                  dialog.getDialogPane().getProperties().put(PREVIOUS_HEIGHT, dialog.getHeight());
              });
              dialog.setOnShown(evt -> {
                  final double previousWidth = (double) dialog.getDialogPane().getProperties().get(PREVIOUS_WIDTH);
                  final double previousHeight = (double) dialog.getDialogPane().getProperties().get(PREVIOUS_HEIGHT);
                  if (previousWidth > 0 && previousHeight > 0) {
                      dialog.setWidth(previousWidth);
                      dialog.setHeight(previousHeight);
                  }
              });
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      On dialog.setOnShowing, remember the dialog's current width and height. On dialog.setOnShown, use dialog.setWidth and dialog.setHeight with the remembered sizes.

      Attachments

        Issue Links

          Activity

            People

              pbansal Pankaj Bansal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: