JavaFX从AnchorPane中删除对象

时间:2015-06-30 19:30:53

标签: java javafx clear

我有

AnchorPane root

root中的HBox

HBox中的两个VBox,每个都是无名的,新的AnchorPane 每个AnchorPane中带有文本

的无名标签

有桌子,只有模板不适合我。

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

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

并重新创建表格。但令人遗憾的是,以前的内容来自root。我该如何删除它?

1 个答案:

答案 0 :(得分:1)

要从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>,因此您可以访问所有这些方法。

相关问题