0
我創建了這個我希望在顯示確認對話框後關閉的標籤示例,點擊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;
}
我有這個問題:當我點擊選項卡關閉它時,選項卡關閉並顯示確認對話框。我無法「凍結」用戶響應的選項卡。你能告訴我如何解決這個問題嗎?
有沒有其他'EventHandler'我可以使用ti在JavaFX 2.2中獲得相同的效果?例如,當我點擊'X'並在活動標籤上調用close()時調用Dialog? – user1285928
我已經破解了這個支持到2.2見https://git.eclipse.org/c/efxclipse/org.eclipse.efxclipse.git/tree/bundles/runtime/org.eclipse.fx.e4.controls.fx2/ SRC /組織/蝕/ FX/E4 /控制/ FX2 – tomsontom