我创建了这个选项卡示例,我想在显示确认对话框并单击Yes按钮后关闭它。
public static Tab testconfirmTabClose(Tab tab)
    {
        tab.setOnClosed(new EventHandler<Event>()
        {
            @Override
            public void handle(Event t)
            {
                t.consume();
                // Dialog Stage init
                final Stage dialog = new Stage();
                dialog.initModality(Modality.APPLICATION_MODAL);
                Button btnYes = new Button("Yes");
                btnYes.setOnAction(new EventHandler<ActionEvent>()
                {
                    @Override
                    public void handle(ActionEvent event)
                    {
                        dialog.close();
                    }
                });
                Button btnNo = new Button("No");
                btnNo.setOnAction(new EventHandler<ActionEvent>()
                {
                    @Override
                    public void handle(ActionEvent event)
                    {
                        dialog.close();
                    }
                });
                // Layout for the Button
                HBox hbox = new HBox();
                hbox.setSpacing(10);
                hbox.setAlignment(Pos.CENTER);
                hbox.getChildren().add(btnYes);
                hbox.getChildren().add(btnNo);
                // Layout for the Label and hBox
                VBox vbox = new VBox();
                vbox.setAlignment(Pos.CENTER);
                vbox.setSpacing(10);
                // Text
                Text tc = new Text();
                tc.setText("Do you want to quit?");
                // Layout for the Button
                HBox thbox = new HBox();
                thbox.setSpacing(10);
                thbox.setPadding(new Insets(20, 20, 20, 90));   // Place the dialog text right
                thbox.setAlignment(Pos.CENTER_LEFT);
                thbox.getChildren().add(tc);
                BorderPane bp = new BorderPane();
                bp.setPadding(new Insets(15, 15, 10, 15));
                bp.setTop(null);
                bp.setLeft(vbox);
                bp.setCenter(thbox);
                bp.setRight(null);
                bp.setBottom(hbox);
                Scene scene = new Scene(bp, 500, 140);
                dialog.setScene(scene);
                dialog.show();
            }
        });
        return tab;
    }
我有这个问题:当我单击选项卡将其关闭时,选项卡将关闭并显示确认对话框。我无法“冻结”用户响应的选项卡。你能告诉我如何解决这个问题吗?