[英]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.