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

GridPane ColumnConstraints Java 7 and 8 broken compatibility

    XMLWordPrintable

Details

    Description

      Steps to reproduce:
      1) run the following example using Java 7 and again using Java 8:
      {code:java}
      import java.util.ArrayList;
      import java.util.List;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.GridPane;
      import javafx.stage.Stage;

      public class BetpalFXApplication extends Application {

       

          @Override
          public void start(Stage stage) throws Exception {
              GridPane root = createGrid();
              stage.setScene(new Scene(root));
              stage.show();
          }

       

          private GridPane createGrid() {
              BorderPane left = new BorderPane();
              left.setStyle("-fx-background-color: red");
              left.setCenter(new Label("left"));
              BorderPane middle = new BorderPane();
              middle.setStyle("-fx-background-color: yellow");
              middle.setCenter(new Label("middle"));
              BorderPane right = new BorderPane();
              right.setStyle("-fx-background-color: blue");
              right.setCenter(new Label("right"));

              GridPane root = new GridPane();
              double[] widthPercentColumnConstraintsThree = { 33.3, 33.3, 33.3 };
              setColumnConstraints(root, widthPercentColumnConstraintsThree);
              root.add(left, 0, 0);
              root.add(middle, 1, 0);
              root.add(right, 2, 0);
              return root;
          }

       

          private void setColumnConstraints(GridPane gridPane, double[] widthPercentColumnConstraints) {

              List<ColumnConstraints> listOfColumnConstraints = new ArrayList<ColumnConstraints>();

              for (double widthPercentColumnConstraint : widthPercentColumnConstraints) {

                  ColumnConstraints columnConstraints = new ColumnConstraints();

                  columnConstraints.setPercentWidth(widthPercentColumnConstraint);

                  listOfColumnConstraints.add(columnConstraints);

              }

              gridPane.getColumnConstraints().setAll(listOfColumnConstraints);

          }

       

          public static void main(String[] args) {

              Application.launch(args);

          }

      }
      {code}

      Expected result:
      We can see the same result using both Java 7 and 8 which is a small window containing colorful grid pane with 3 equal size columns.

      Actual result:
      We see the expected result for Java 7 and very wide window in Java 8.

      Notes:
      We know that 33.3 + 33.3 + 33.3 != 100 but it worked in Java 7.
      Using { 33.3, 33.3, 33.4 } usually helps BUT in some cases if you use { 33.3, 33.4, 33.3 } it doesn't work even though it's sum is 100. ( see https://community.oracle.com/thread/3537869 )

      Attachments

        Activity

          People

            msladecek Martin Sládeček
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: