gpt4 book ai didi

JavaFX 从 AnchorPane 中删除对象

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:58:46 25 4
gpt4 key购买 nike

我有

AnchorPane根

根目录下的HBox

HBox中有两个VBox,每个都没有名字,new AnchorPane和带有文本的每个 AnchorPane 中的无名标签

有表格,只是模板不适合我。

当我需要在具有新内容的同一个点表上构建新表时,我会这样做:

    root.clearConstraints(hBox);
hBox = new HBox();
root.getChildren().add(hBox);

然后重新创建表。但可悲的是,之前来自 root 的内容仍然存在。我怎样才能删除它?

最佳答案

Pane 中删除项目,您需要将它们从其子项中移除。您有多种选择:

root.getChildren().remove(hBox); // remove a single item
root.getChildren().removeAll(box1, box2, box3); // remove all listed items (varargs)
root.getChildren().removeAll(collectionOfNodes); // remove all items in a Collection
root.getChildren().clear(); // remove all children

还有其他的:getChildren()返回 ObservableList<Node> , 它扩展了 List<Node> ,因此您可以访问所有这些方法。

关于JavaFX 从 AnchorPane 中删除对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31146861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com