2017-03-16 148 views
1
tab.setOnCloseRequest(e -> { 
       e.consume(); 
       if (currentEditor.isModified()){ 
        switch (DialogBox.newSaveConfirmationBox(tab.getText())){ 
         case "Yes": tabPane.fireEvent(???); 
        } 
       } 
      } 

我想對選項卡式文本編輯器進行確認,其中有操作「是」「否」取消「。是否有方法來觸發關閉選項卡事件時」是「被選中?謝謝JavaFX火災關閉標籤事件

tab.setOnCloseRequest(e -> { 
       if (currentEditor.isModified()){ 
        switch (DialogBox.newSaveConfirmationBox(tab.getText())){ 
         case "Yes": 
          saveFile(); 
         case "Cancel": 
          e.consume(); 
        } 
       } 
      } 
    ); 

可悲的是,當currentEditor.isModified()false,標籤不能關閉,有什麼建議?謝謝

+0

找到您需要的一個。 http://code.makery.ch/blog/javafx-dialogs-official/。我猜你需要一個確認對話框。 – Sedrick

回答

2

使用該事件的否決權接近。所以,你應該只消耗如果事件用戶決定他們不想關閉標籤,否則讓事件傳播,並且標籤將關閉:

tab.setOnCloseRequest(e -> { 
    // remove the next line: you only want to consume the event for "No" 
    // e.consume(); 
    if (currentEditor.isModified()){ 
     if ("No".equals(DialogBox.newSaveConfirmationBox(tab.getText()))) { 
      e.consume(); 
     } 
    } 
});