在我FXML我已經在AnchorPane得到了FlowPane:更改Node.height即刻Node.prefHeight(AnchorPane)
的AnchorPane應儘快FlowPane需要另一行改變其高度。我試圖在Flowpane.heightProperty上創建一個改變的偵聽器,它工作。然後,我將AnchorPane的高度設置爲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
我不能老是認爲我是第一個問這個問題。