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

StackPane is ignoring the max size of its only child (GridPane) and resizing it anyway

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: fx2.1
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Environment:

      JavaFX 2.1b14 32-bit, Windows 7 64-bit

      Description

      Run the example. What you should see is a small GridPane (size 300x300), but what you get is a (more than) full screen spanning GridPane.

      According to StackPane's docs:

      "The stackpane will attempt to resize each child to fill its content area. If the child could not be sized to fill the stackpane (either because it was not resizable or its max size prevented it) then it will be aligned within the area using the alignment property, which defaults to Pos.CENTER."

      Clearly the GridPane's max size should prevent it being resized and it should be positioned in the center.

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.RowConstraints;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class GridPaneMaxSizeTest extends Application {
        public static void main(String[] args) {
          Application.launch(args);
        }

        @Override
        public void start(Stage stage) throws Exception {
          StackPane stackPane = new StackPane();
          GridPane gridPane = new GridPane();

          gridPane.getColumnConstraints().add(new ColumnConstraints() {{
            setPercentWidth(10);
          }});
          gridPane.getColumnConstraints().add(new ColumnConstraints() {{
            setPercentWidth(80);
          }});
          gridPane.getColumnConstraints().add(new ColumnConstraints() {{
            setPercentWidth(10);
          }});

          gridPane.getRowConstraints().add(new RowConstraints() {{
            setPercentHeight(10);
          }});
          gridPane.getRowConstraints().add(new RowConstraints() {{
            setPercentHeight(80);
          }});
          gridPane.getRowConstraints().add(new RowConstraints() {{
            setPercentHeight(10);
          }});

          gridPane.add(new ImageView() {{
            setFitWidth(1500);
            setFitHeight(1500);
          }}, 1, 1);

          gridPane.setGridLinesVisible(true);
          gridPane.setPrefSize(300, 300);
          gridPane.setMaxSize(300, 300);

          stackPane.getChildren().add(gridPane);

          Scene scene = new Scene(stackPane);

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

        Attachments

          Activity

            People

            • Assignee:
              kwwong Kinsley Wong
              Reporter:
              jhendrikx John Hendrikx
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: