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

Dialog Window is not sized to show its content

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "9-ea"
      Java(TM) SE Runtime Environment (build 9-ea+165)
      Java HotSpot(TM) 64-Bit Server VM (build 9-ea+165, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux machine 4.10.10-1.ga78ebd0-default #1 SMP PREEMPT Wed Apr 12 11:18:29 UTC 2017 (a78ebd0) x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)
      KDE Plasma 4.8
      GTK2 2.24.31-12.1
      GTK3 3.20.10-3.1
      Mesa 17.0.4-666.2
      xorg-x11-server 1.19.3-488.21

      A DESCRIPTION OF THE PROBLEM :
      A regression in JavaFX Dialog window size.

      Setting the Width and Height of the Dialog does not work. Regardless if they are set or not, the dialog window was not sized up to show the content.
      None of these works:
      setWidth(300);
      setHeight(300);
      getDialogPane().setMinSize(300, 300);
      getDialogPane().setPrefSize(300, 300);

      If I call setResizable(true) on the dialog then the full dialog window is shown. Even if its size was not set.
      Size is only respected if Dialog is resizable. It is a problem if the dialog should not be resizable.

      This works fine running in JDK 9 build 161, but not in JDK 9 build 165.
       
      The application was built with JDK 8u121 and used javapackager to create the runnable JAR.

      username@machine:~/workspace/javafx-test> /usr/java/jdk-9/bin/java -jar javafx-test-1.0-SNAPSHOT.jar
      Gtk-Message: Failed to load module "canberra-gtk-module"

      (java:28023): Gtk-WARNING **: Unable to locate theme engine in module_path: "ubuntulooks",

      (java:28023): Gtk-WARNING **: Unable to locate theme engine in module_path: "crux-engine",
      Gtk-Message: (for origin information, set GTK_DEBUG): failed to retrieve property `gtk-primary-button-warps-slider' of type `gboolean' from rc file value "((GString*) 0x7fb9342bf940)" of type `gboolean'

      (java:28023): Gtk-WARNING **: Unable to locate theme engine in module_path: "ubuntulooks",

      (java:28023): Gtk-WARNING **: Unable to locate theme engine in module_path: "crux-engine",


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and build with Java 8.
      Run with Java 9.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Dialog window size should be big enough to at least show its content.
      ACTUAL -
      Dialog window has barely any size. Only a small portion of the dialog content is visible.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package javafx.test;

      import java.util.Optional;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.AnchorPane;
      import javafx.stage.Stage;
      import javafx.util.Pair;

      public class AppTest extends Application {

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

          public void start(Stage stage) throws Exception {
              Label label = new Label("Hello World!");

              AnchorPane root = new AnchorPane();
              root.getChildren().add(label);

              PasswordDialog login = new PasswordDialog("username", "password");
              Optional<Pair<String, String>> result = login.showAndWait();

              stage.setScene(new Scene(root));
              stage.setWidth(100);
              stage.setHeight(50);
              stage.setTitle("JavaFX 8 app");
              stage.show();
          }

      }

      package javafx.test;

      import javafx.application.Platform;
      import javafx.scene.control.Button;
      import javafx.scene.control.ButtonType;
      import javafx.scene.control.Dialog;
      import javafx.scene.control.Label;
      import javafx.scene.control.PasswordField;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.BackgroundFill;
      import javafx.scene.layout.GridPane;
      import javafx.scene.paint.Color;
      import javafx.util.Pair;

      public class PasswordDialog extends Dialog<Pair<String, String>> {

          private String password;

          private String userName;

          public PasswordDialog(String userName, String password) {
              super();
              this.userName = userName;
              this.password = password;

              build();
              getDialogPane().getScene().getWindow().centerOnScreen();
              setOnCloseRequest(event -> Platform.setImplicitExit(true));
          }

          private void build() {
              getDialogPane().setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
              setTitle("Login");

              getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CLOSE);

              GridPane grid = new GridPane();
              grid.setHgap(10);
              grid.setVgap(10);

              grid.add(new Label("Username"), 0, 1);

              TextField userNameField = new TextField();
              grid.add(userNameField, 1, 1);

              grid.add(new Label("Password"), 0, 2);

              PasswordField passwordField = new PasswordField();
              grid.add(passwordField, 1, 2);

              // Enable/Disable login button depending on whether a username was entered.
              Button loginButton = (Button) getDialogPane().lookupButton(ButtonType.OK);
              loginButton.setText("Login");
              loginButton.setDisable(true);
              loginButton.setOnAction(event -> Platform.setImplicitExit(false));

              Button cancelButton = (Button) getDialogPane().lookupButton(ButtonType.CLOSE);
              cancelButton.setText("Cancel");

              getDialogPane().setContent(grid);

              setResultConverter(dialogButton -> {
                  if (dialogButton == ButtonType.OK) {
                      return new Pair<>(userNameField.getText(), passwordField.getText());
                  }
                  return null;
              });

              this.password = passwordField.getText();
              this.userName = userNameField.getText();
          }

          public String getPassword() {
              return password;
          }

          public String getUserName() {
              return userName;
          }

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      setResizable(true);

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pbansal Pankaj Bansal
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: