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

GridPane does not compute prefWidth correctly in case of percentWidths and hGaps

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 9
    • 8u74
    • javafx
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      GridPane's computeTotalWithMultiSize method grows the total size for percentWidths without taking gaps into consideration. This results in gaps cutting of the contents of the content, because the GridPane is not big enough.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Load this GridPane FXML as a root of a Scene within a Stage, and display the stage.

      <?xml version="1.0" encoding="UTF-8"?>

      <?import javafx.scene.control.Label?>
      <?import javafx.scene.layout.ColumnConstraints?>
      <?import javafx.scene.layout.GridPane?>
      <GridPane xmlns="http://javafx.com/javafx/8" hgap="5">
          <columnConstraints>
              <ColumnConstraints percentWidth="50"/>
              <ColumnConstraints percentWidth="50"/>
          </columnConstraints>

          <Label text="00000000001"/>
          <Label text="0000000000" GridPane.columnIndex="1"/>
      </GridPane>


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The layout should show the labels correctly, with all of them having _at least_ their preferred sizes.
      ACTUAL -
      The last 2 characters of the first label is cut off and replaced with "...".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package gui.test;

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

      public class GridPaneLayoutTest extends Application {
          @Override
          public void start(Stage primaryStage) throws Exception {
              GridPane gridPane = new GridPane();

              gridPane.setHgap(5);

              ColumnConstraints columnConstraints1 = new ColumnConstraints();
              ColumnConstraints columnConstraints2 = new ColumnConstraints();
              columnConstraints1.setPercentWidth(50);
              columnConstraints2.setPercentWidth(50);
              gridPane.getColumnConstraints().add(columnConstraints1);
              gridPane.getColumnConstraints().add(columnConstraints2);

              gridPane.add(new Label("00000000001"), 0, 0);
              gridPane.add(new Label("0000000000"), 1, 0);

              final Scene scene = new Scene(gridPane);

              Stage stage = new Stage();
              stage.setScene(scene);

              stage.show();

          }

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

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

            ckyang Chien Yang (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: