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


    • 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


      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) {

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

          gridPane.getColumnConstraints().add(new ColumnConstraints() {{
          gridPane.getColumnConstraints().add(new ColumnConstraints() {{
          gridPane.getColumnConstraints().add(new ColumnConstraints() {{

          gridPane.getRowConstraints().add(new RowConstraints() {{
          gridPane.getRowConstraints().add(new RowConstraints() {{
          gridPane.getRowConstraints().add(new RowConstraints() {{

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

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


          Scene scene = new Scene(stackPane);





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


              • Created: