【发布时间】:2022-01-05 05:58:17
【问题描述】:
在此处输入图像描述我在 JavaFX 上制作了一个用于创建时间表的 GUI。当我打开应用程序时,我可以将计划(按钮)添加到日列(VBox)。在我关闭应用程序后,更改不会保存:下次我打开它时,表格是空的。 我的问题是如何让它保存用户创建的节点,以便下次我打开应用程序时它们在那里?
这是添加节点的确切部分:
void ask_add_plan(ActionEvent event)
{
Button b = (Button) event.getSource();
VBox v = (VBox) b.getParent();
AnchorPane pop_up = new AnchorPane(); //this pop up is to specify things about the plan
//but i removed unnecessary code for simplicity
VBox pop_up_v = new VBox();
Button add = new Button("Add");
add.setOnAction(e->{
Button plan = new Button(what_to_do.getText());
v.getChildren().add(plan);
container.getChildren().remove(pop_up); //container is the anchor pane everything's in
});
pop_up_v.getChildren().add(add);
pop_up.getChildren().add(pop_up_v);
container.getChildren().add(pop_up); //container is the anchor pane everything's in
}
【问题讨论】:
-
请遵守 java 命名约定 - 至于问题:不要保存节点,而是对状态进行建模并保存模型
标签: java user-interface javafx save nodes