我有这个上下文菜单,可以选择在新窗口中显示选项卡内容并关闭 TabPane 选项卡:
MenuItem item5 = new MenuItem("Open Tab In Stand-Alone Window");
item5.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
System.out.println("Open Tab In Stand-Alone Window");
Node test = tab.getContent();
NavMenu.standAloneTab(test);
tabPane.getTabs().remove(tab);
}
});
带有标签内容的新对话框:
public static void standAloneTab(Node tab)
{
final int xSize = 640;
final int ySize = 480;
final Color backgroundColor = Color.WHITESMOKE;
Stage newConnDialog = new Stage();
newConnDialog.initModality(Modality.WINDOW_MODAL);
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 20, 20, 20));
grid.add(tab, 0, 0);
Scene aboutDialogScene = new Scene(grid, xSize, ySize, backgroundColor);
newConnDialog.setScene(aboutDialogScene);
newConnDialog.show();
}
当我选择Open Tab In Stand-Alone Window
带有选项卡内容的新窗口时,旧选项卡未关闭。如果我打电话tabPane.getTabs().remove(tab);
关闭标签,新窗口是空的。
如何在不删除内容的情况下关闭选项卡?
编辑
我以这种方式更新了代码:
MenuItem item5 = new MenuItem("Open Tab in Stand-alone Window");
item5.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent e)
{
System.out.println("Open Tab In Stand-Alone Window");
Node openedTab = tab.getContent();
NavMenu.standAloneTab(tabPane, openedTab);
//tabPane.getTabs().remove(tab);
}
});
和新的对话框:
public static void standAloneTab(final TabPane tabPane, final Node tab)
{
Stage newConnDialog = new Stage();
newConnDialog.initModality(Modality.WINDOW_MODAL);
newConnDialog.setOnShown(new EventHandler<WindowEvent>()
{
@Override
public void handle(WindowEvent t)
{
tabPane.getTabs().remove(tab);
}
});
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(20, 20, 20, 20));
grid.add(tab, 0, 0);
Scene aboutDialogScene = new Scene(grid, 700, 500, Color.WHITESMOKE);
newConnDialog.setScene(aboutDialogScene);
newConnDialog.show();
}
我更新了代码,但得到了相同的结果。