有没有办法可以在 javafx 中动态添加一个永久选项卡?我的意思是,我已经创建了一个可以在单击按钮时动态添加选项卡的代码,但是当我关闭窗口并再次打开它时,我刚刚添加的选项卡就消失了。
这是我的代码片段..
//on button click
@FXML
private void addNewTab(ActionEvent event) {
add_tab_button.setOnAction(e -> {
main_tab.getTabs().add(createTab()); //main_tab is the TabPane
main_tab.getSelectionModel().selectLast();
});
}
//the new tab to be created
private Tab createTab() {
tabIndex++;
Tab newTab = new Tab ("Tab " + tabIndex);
//content of tab goes here..
return newTab;
}
一切顺利,除了,再次,当我关闭窗口并再次打开它时,新创建的选项卡被删除..有没有办法永久添加它?好像我正在覆盖视图的 fxml 文件?