Markai
Markai

Reputation: 2098

Binding prefWidthProperty of ListView to widthProperty of containing AnchorPane breaks resizing of AnchorPane

I have a TabPane which contains two Tabs and is set up in FXML. On initialization I dynamically add an AnchorPane to one of the Tabs. I then set a ListView as a child of the AnchorPane:

AnchorPane questionPane = new AnchorPane();
questionPane.setId("questionPane");
ListView questionList = new ListView();
questionPane.getChildren().add(questionList);

This works perfectly fine. For debugging purposes I gave the AnchorPane an orange background (via CSS) and when I now resize the window, the AnchorPane get's resized as expected.
But as soon as I add the following line to the code, the AnchorPane can only grow and doesn't shrink anymore, resulting in outsizing my window:

questionList.prefWidthProperty().bind(questionPane.widthProperty());

Can anyone please explain, why this line breaks the resizing of the AnchorPane?

Upvotes: 0

Views: 767

Answers (1)

javaHunter
javaHunter

Reputation: 1097

Most likely you didn't specify the anchoring of the ListView:

AnchorPane.setBottomAnchor(questionList , 8.0);
AnchorPane.setRightAnchor(questionList , 5.0);
AnchorPane.setTopAnchor(questionList , 8.0);
AnchorPane.setLeftAnchor(questionList , 5.0);

The binding is not needed anymore.

Upvotes: 1

Related Questions