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();
}
}
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();
}
}
- is blocked by
-
JDK-8092725 Constraints are not working on GridPane
- Closed