【发布时间】:2016-10-30 20:31:50
【问题描述】:
在我的 fxml 中,我在 AnchorPane 中有一个 FlowPane:
一旦 FlowPane 需要另一行,AnchorPane 就应该改变它的高度。我试图在 Flowpane.heightProperty 上更改监听器并且它有效。然后我将 AnchorPane 的 prefHeight 设置为 flowPane 的新高度,因为我无法设置高度。问题是 AnchorPane 不会立即调整大小。 prefHeight 会随着我想要的改变而改变,但高度不会改变。在我将鼠标拖到 FlowPane 上后,它会发生变化。
代码:
FlowPane flowPane = new FlowPane();
AnchorPane anchorPane = new AnchorPane(flowPane);
titleAnchorPane.setTopAnchor(titleFlowPane, 0.0);
titleAnchorPane.setLeftAnchor(titleFlowPane, 0.0);
titleAnchorPane.setRightAnchor(titleFlowPane, 0.0);
flowPane.heightProperty().addListener((observable, oldValue, newValue) -> {
anchorPane.setPrefHeight(newValue.doubleValue());
});
Bevore I dragged my mouse over it
After I dragged my mouse over it
我不敢相信我是第一个问这个问题的人。
【问题讨论】:
标签: java validation javafx properties refresh