我有一个 TabPane
,其中包含两个 Tab
,并在 FXML
中设置。初始化时,我动态地将 AnchorPane
添加到 Tab
之一。然后,我将 ListView
设置为 AnchorPane
的子级:
AnchorPane questionPane = new AnchorPane();
questionPane.setId("questionPane");
ListView questionList = new ListView();
questionPane.getChildren().add(questionList);
这工作得很好。出于调试目的,我为 AnchorPane
提供了橙色背景(通过 CSS
),当我现在调整窗口大小时,AnchorPane
会按预期调整大小。
但是,一旦我将以下行添加到代码中,AnchorPane
就只能增大而不再缩小,从而导致窗口过大:
questionList.prefWidthProperty().bind(questionPane.widthProperty());
谁能解释一下,为什么这一行会破坏 AnchorPane
的大小调整?
最佳答案
很可能您没有指定 ListView 的锚定:
AnchorPane.setBottomAnchor(questionList , 8.0);
AnchorPane.setRightAnchor(questionList , 5.0);
AnchorPane.setTopAnchor(questionList , 8.0);
AnchorPane.setLeftAnchor(questionList , 5.0);
不再需要绑定(bind)。
关于java - 将 ListView 的 prefWidthProperty 绑定(bind)到包含 AnchorPane 的 widthProperty 会破坏 AnchorPane 的大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27424673/