[英]JavaFX delete objects from AnchorPane
我有
AnchorPane 根
根目录下的 HBox
HBox中的两个VBox,每一个都是无名的,每个AnchorPane中的new AnchorPane和无名Label有文字
有桌子,只是一个模板不适合我。
当我需要使用新内容在同一个点表上构建新表时,我会这样做:
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>
,因此您可以访问所有这些方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.