【发布时间】:2017-12-04 22:53:09
【问题描述】:
在 JavaFX 中,我在容器窗格内的 AnchorPane(或 StackPane)内有一个标签(或 TextFlow)。
容器窗格的高度是无限的,但它的宽度固定为我想要的任何值。
我需要:
1) AnchorPane 的宽度填充所有可用空间,但不大于标签在一行中的宽度。
2) 标签为多行 (wrap=true) 并填充所有可用空间。
3) AnchorPane 的高度要等于 Label 的高度。
代码设置:
Pane rootPane = new Pane();
rootPane.setBackground(new Background(new BackgroundFill(Color.FIREBRICK, CornerRadii.EMPTY, Insets.EMPTY)));
AnchorPane anchorPane = new AnchorPane();
anchorPane.setBackground(new Background(new BackgroundFill(Color.FORESTGREEN, CornerRadii.EMPTY, Insets.EMPTY)));
Label text = new Label("text text text text text text text text text text text");
anchorPane.getChildren().add(text);
rootPane.getChildren().add(anchorPane);
或者,我可以使用以下标签:
TextFlow text = new TextFlow(new Text("text text text text text text text text text text text"));
我在这个问题上浪费了几个小时。这在 HTML 中是如此简单……我怎样才能做到这一点?
【问题讨论】:
-
发布您的
FXML的简化版本。 -
@SedrickJefferson 我没有 FXML。