-
Bug
-
Resolution: Fixed
-
P4
-
7u6
consider following test case:
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.shape.Line;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class LayoutBoundsTest extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) throws Exception {
BorderPane pane = new BorderPane();
// define center pane.
StackPane center = new StackPane();
center.setStyle("-fx-background-color: coral;");
center.setAlignment(Pos.CENTER_LEFT);
Label someLabel = new Label(" Label Bounds Issue Test");
Line line = new Line(0,0,0,500);
center.getChildren().addAll(line, someLabel);
pane.setCenter(center);
// define left
VBox left = new VBox();
left.setStyle("-fx-background-color: cornsilk;");
left.setMaxWidth(200);
GridPane grid = new GridPane();
grid.setStyle("-fx-background-color: azure;");
grid.add(new Text("Name:"), 0, 0);
grid.add(new Label(
"Karl Theodor Maria Nikolaus Johann Jacob Philipp Franz Joseph Sylvester Freiherr von und zu Guttenberg"
), 1, 0);
left.getChildren().add(grid);
// this bind should not be necessary but is required because
// the layout seems to take up the preferred width of the grid's children rather
// than inheriting the max width through the max width setting of the VBox.
// grid.maxWidthProperty().bind(left.maxWidthProperty());
pane.setLeft(left);
stage.setScene(new Scene(pane, 800, 500));
stage.show();
}
}
This is a BorderPane with a VBox as direct child which contains a GridPane. The GridPane contains a Label with a very long text.
The VBox maxWidth is set so that all children of the VBox do not grow larger than that value. However, although the Label in the GridPane is truncated at the correct index to fit this value, container of the VBox is made as large as the Label. This is indicated by the large amount of white space between the nodes.
When a value is set to the maxWidth property of the GridPane, the layout is calculated correctly.
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.shape.Line;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class LayoutBoundsTest extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) throws Exception {
BorderPane pane = new BorderPane();
// define center pane.
StackPane center = new StackPane();
center.setStyle("-fx-background-color: coral;");
center.setAlignment(Pos.CENTER_LEFT);
Label someLabel = new Label(" Label Bounds Issue Test");
Line line = new Line(0,0,0,500);
center.getChildren().addAll(line, someLabel);
pane.setCenter(center);
// define left
VBox left = new VBox();
left.setStyle("-fx-background-color: cornsilk;");
left.setMaxWidth(200);
GridPane grid = new GridPane();
grid.setStyle("-fx-background-color: azure;");
grid.add(new Text("Name:"), 0, 0);
grid.add(new Label(
"Karl Theodor Maria Nikolaus Johann Jacob Philipp Franz Joseph Sylvester Freiherr von und zu Guttenberg"
), 1, 0);
left.getChildren().add(grid);
// this bind should not be necessary but is required because
// the layout seems to take up the preferred width of the grid's children rather
// than inheriting the max width through the max width setting of the VBox.
// grid.maxWidthProperty().bind(left.maxWidthProperty());
pane.setLeft(left);
stage.setScene(new Scene(pane, 800, 500));
stage.show();
}
}
This is a BorderPane with a VBox as direct child which contains a GridPane. The GridPane contains a Label with a very long text.
The VBox maxWidth is set so that all children of the VBox do not grow larger than that value. However, although the Label in the GridPane is truncated at the correct index to fit this value, container of the VBox is made as large as the Label. This is indicated by the large amount of white space between the nodes.
When a value is set to the maxWidth property of the GridPane, the layout is calculated correctly.