In my fxml I have got a FlowPane in an AnchorPane:
The AnchorPane should change its height as soon as the FlowPane needs another line. I tried to make a changed listener on the Flowpane.heightProperty and it worked. Then I set the prefHeight of the AnchorPane to the new height of the flowPane because I can`t set the height. The problem is that the AnchorPane does not resize instantly. The prefHeight changes as I want it to change, but the height not. It changes after I drag my mouse over the FlowPane.
Code:
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
I can`t believe that I am the first one asking this question.