我有一个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 get的大小按预期进行了调整。
但是,一旦我在代码中添加了下面一行,AnchorPane就只能增长,不再缩小,从而导致窗口的大小过大:
questionList.prefWidthProperty().bind(questionPane.widthProperty());有谁能解释一下,为什么这一行中断了AnchorPane的大小调整?
发布于 2014-12-11 14:17:20
很可能没有指定ListView的锚定:
AnchorPane.setBottomAnchor(questionList , 8.0);
AnchorPane.setRightAnchor(questionList , 5.0);
AnchorPane.setTopAnchor(questionList , 8.0);
AnchorPane.setLeftAnchor(questionList , 5.0);已经不需要绑定了。
https://stackoverflow.com/questions/27424673
复制相似问题