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

Scene does not initially fill a Stage with a minimum size

XMLWordPrintable

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


      ADDITIONAL OS VERSION INFORMATION :
      Linux Workstation 4.10.0-21-generic #23-Ubuntu SMP Fri Apr 28 16:14:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      I have encountered this issue on Ubuntu GNOME 16.10 and 17.04, and my coworker has seen the same issue on an unknown version of Xubuntu. I would guess that it affects all platforms that use the Gtk backend of JavaFX.

      A DESCRIPTION OF THE PROBLEM :
      Our application has a minimum window size that we enforce by calling Stage#setMinWidth and Stage#setMinHeight. This works fine on Windows and macOS, but on Linux, the Scene will not fill the Stage until the window has been resized once. (See example below.)

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

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      There should be a 1000x1000px window filled with a single label with a red background..
      ACTUAL -
      The label is shown at its tiny preferred size, and the rest of the window is grey. Once the window is resized, the label/scene suddenly fill the window as expected.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package sample;

      import javafx.application.Application;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.*;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;

      public class Main extends Application {
          @Override
          public void start(Stage primaryStage) throws Exception{
              Label root = new Label("JavaFX Stage: Minimum Size Test");
              root.setAlignment(Pos.CENTER);
              root.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));
              primaryStage.setScene(new Scene(root));
              primaryStage.setMinWidth(1000);
              primaryStage.setMinHeight(1000);
              primaryStage.show();
          }

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

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

      CUSTOMER SUBMITTED WORKAROUND :
      If we also pass the minimum stage size into the Scene constructor, the scene will use that as its initial size: "new Scene(root, 1000, 1000)".

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

              Created:
              Updated:
              Resolved: