将标签添加到添加到另一个窗格的窗格时,我遇到了布局问题。
就像在这个例子中一样:
public class MyClass extends Pane {
private final Pane myPane;
public MyClass() {
this.myPane.prefWidthProperty().bind(this.widthProperty);
this.myPane.prefHeightProperty().bind(this.heightProperty);
this.getChildren().add(this.myPane);
}
@Override
layoutChildren() {
this.foo();
}
private void foo() {
this.myPane.getChildren().add(new Label("foo"));
}
}
问题是它只是无限地调用 layoutChildren。奇怪的一件事是,如果我添加文本而不是标签,则不会出现“问题”。
我检查了每个节点的大小,它们没有改变。在我看来,有人正在扩展,因此调用了布局,但我就是找不到在哪里。
我错过了什么微不足道的东西吗?