When a label with text wrapping on is placed in a VBox, wrapping of the label becomes completely disabled if the VBox's fillWidth is set to false. A wrapped label has a horizontal content bias, and its height functions should be called with the result of its width functions, yet VBox in these cases will always call them with -1.
The root cause seems to be in Region's computeChildArea* functions, which have differences in the width and height versions. The width versions take a fillHeight parameter, allowing to pass a height other than -1 with fillHeight set to false. The height versions of these functions only take a width, which is forced to -1 if fillWidth is set to false by the caller (VBox in this case). However, this disables the content bias system.
Run attached program to see the problem.
The solution seems to be to fix the discrepancies between the computeChildArea functions, and introducing a separate fillWidth parameter for the height variants.
public class App extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
Label label1 = new Label("Relatively long text that may need wrapping at some point");
label1.setWrapText(true); // make it get a horizontal bias
VBox root = new VBox(label1);
root.setStyle("-fx-font-size: 50px");
root.setFillWidth(false); // breaks label reflow
Scene value = new Scene(root, 300, 500);
primaryStage.setScene(value);
primaryStage.show();
}
}
The root cause seems to be in Region's computeChildArea* functions, which have differences in the width and height versions. The width versions take a fillHeight parameter, allowing to pass a height other than -1 with fillHeight set to false. The height versions of these functions only take a width, which is forced to -1 if fillWidth is set to false by the caller (VBox in this case). However, this disables the content bias system.
Run attached program to see the problem.
The solution seems to be to fix the discrepancies between the computeChildArea functions, and introducing a separate fillWidth parameter for the height variants.
public class App extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
Label label1 = new Label("Relatively long text that may need wrapping at some point");
label1.setWrapText(true); // make it get a horizontal bias
VBox root = new VBox(label1);
root.setStyle("-fx-font-size: 50px");
root.setFillWidth(false); // breaks label reflow
Scene value = new Scene(root, 300, 500);
primaryStage.setScene(value);
primaryStage.show();
}
}
- links to
-
Commit(master) openjdk/jfx/a550e5e4
-
Review(master) openjdk/jfx/1723