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

Using baseline alignment in GridPane causes incorrect layout of long texts

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u31
    • javafx
    • win 7 x64, java jdk 8_u31 x64

      When I put a TextFlow with a long text into a Gridpane and use a baseline alignment the height of the row is calculated incorrectly so that the TextFlow extends beyond the lower border of the GridPane.

      The same problem happens when using a label with wrapText = true, however in this case instead of wrapping the text an ellipsis in introduced.

      Example code:

      package bugreports;

      import javafx.application.Application;
      import javafx.geometry.VPos;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.*;
      import javafx.scene.text.Text;
      import javafx.scene.text.TextFlow;
      import javafx.stage.Stage;

      public class TextFlowInGridPaneIgnoringHeight extends Application
      {
      private final String text = "Nunc eu elit augue. Vivamus viverra ullamcorper enim, eu porta eros placerat " +
      "sit amet. Donec interdum at sem ut bibendum. Vestibulum tristique libero erat, sit amet sollicitudin " +
      "ex convallis in. Nam rhoncus arcu quis justo varius, sit amet tristique arcu porttitor. " +
      "Maecenas eget dapibus erat. Donec malesuada bibendum feugiat. Etiam pellentesque velit quam.";

      @Override
      public void start(final Stage primaryStage) throws Exception
      {
      final TextFlow flow = new TextFlow(new Text(text));

      // this instead of the TextFlow triggers the same bug:
      final Label label = new Label(text);
      label.setWrapText(true);


      final RowConstraints constraints = new RowConstraints();

      // uncomment to remove bug
      constraints.setValignment(VPos.BASELINE);

      final GridPane pane = new GridPane();
      pane.getRowConstraints().add(constraints);

      pane.getChildren().add(flow);
      // pane.getChildren().add(label);

      pane.setStyle("-fx-background-color: red");

      final VBox container = new VBox(pane);
      container.setMaxWidth(200);
      container.setPrefHeight(400);

      primaryStage.setScene(new Scene(container));
      primaryStage.show();
      }
      }


            Unassigned Unassigned
            cmuthingjfx Clemens Muthing (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Imported: