JavaFX 从锚定面板中清除所有节点并在运行时添加新节点
JavaFX clearing all nodes from anchorpane and adding new nodes during runtime
我在运行时无法将节点添加回 AnchorPane
。
我想做的是,当用户单击一个按钮时,当前节点存储在 ObservableList<Node>
中,然后 AnchorPane
被清除。在此之后我需要在那里添加新节点。然后当用户完成后,他们单击另一个按钮,我保存的 ObservableList
应该被添加回 AnchorPane
。
基本上,我试图在用户单击 "Customer" 按钮时显示客户信息表单,然后显示开始时的节点。
有没有其他方法可以做到这一点?不在另一个 window 中显示?
我使用 .addAll()
但这不起作用。
谢谢。
private ObservableList<Node> middlePaneContent;
@FXML
private AnchorPane middlePane;
@FXML
private void setMiddlePane(){
middlePaneContent = middlePane.getChildren();
//middlePane.setVisible(false);
middlePane.getChildren().clear();
}
@FXML
private void setInspectionToMiddlePane(){
//middlePane.getChildren().addAll(middlePaneContent);
middlePane.setVisible(true);
}
您只是在 middlePaneContent
中存储对 middlePane
的子列表的引用。两者都指向同一个列表。清除其中之一将清除 "other".
使用另一个List
来存储数据:
private List<Node> middlePaneContent = new ArrayList<>();
@FXML
private AnchorPane middlePane;
@FXML
private void setMiddlePane(){
// copy content to another list
middlePaneContent.clear();
middlePaneContent.addAll(middlePane.getChildren());
//middlePane.setVisible(false);
// clear child list
middlePane.getChildren().clear();
}
我在运行时无法将节点添加回 AnchorPane
。
我想做的是,当用户单击一个按钮时,当前节点存储在 ObservableList<Node>
中,然后 AnchorPane
被清除。在此之后我需要在那里添加新节点。然后当用户完成后,他们单击另一个按钮,我保存的 ObservableList
应该被添加回 AnchorPane
。
基本上,我试图在用户单击 "Customer" 按钮时显示客户信息表单,然后显示开始时的节点。
有没有其他方法可以做到这一点?不在另一个 window 中显示?
我使用 .addAll()
但这不起作用。
谢谢。
private ObservableList<Node> middlePaneContent;
@FXML
private AnchorPane middlePane;
@FXML
private void setMiddlePane(){
middlePaneContent = middlePane.getChildren();
//middlePane.setVisible(false);
middlePane.getChildren().clear();
}
@FXML
private void setInspectionToMiddlePane(){
//middlePane.getChildren().addAll(middlePaneContent);
middlePane.setVisible(true);
}
您只是在 middlePaneContent
中存储对 middlePane
的子列表的引用。两者都指向同一个列表。清除其中之一将清除 "other".
使用另一个List
来存储数据:
private List<Node> middlePaneContent = new ArrayList<>();
@FXML
private AnchorPane middlePane;
@FXML
private void setMiddlePane(){
// copy content to another list
middlePaneContent.clear();
middlePaneContent.addAll(middlePane.getChildren());
//middlePane.setVisible(false);
// clear child list
middlePane.getChildren().clear();
}