2016-11-10 23 views
2

ToastBar當我在代碼的任何部分使用它時,它工作正常,但是當我用它來顯示一些消息,即連接完成即。使用它在connectionRequestpostResponse,它不顯示。爲什麼?ToastBar in postResponse of connectionRequest

public boolean abc = false; 
ConnectionRequest cr = new ConnectionRequest(){ 
    @Override 
    protected void postResponse() { 
     abc = true; 
     //update: this toastbar is commented 
     ToastBar.showMessage("Confirmation of your password is sent to your email address", FontImage.MATERIAL_MAIL_OUTLINE,2000); 
    } 

}; 
cr.setPost(true); 
cr.setUrl(AllUrl.forgetPasswordUrl); 
cr.setDuplicateSupported(true); 
cr.setTimeout(30000); 
cr.addArgument("forgetten_email", forgottonEmail); 
InfiniteProgress ip = new InfiniteProgress(); 
Dialog d = ip.showInifiniteBlocking(); 
cr.setDisposeOnCompletion(d); 
NetworkManager.getInstance().addToQueueAndWait(cr); 

UPDATE1: ,在GUI Builder作爲空白對話框創建的窗體。該toastbar不列入工作在這裏,但另一個對話框工作

protected void beforeForgetPasswordDialog(Form f) { 
    TextField emailTextField = new TextField(); 
    f.add(emailTextField); 

    Button submit = new Button("Submit"); 

    submit.addActionListener(e -> { 
     Style s = UIManager.getInstance().getComponentStyle("Label"); 
     String forgottenPasswordEmail = emailTextField.getText(); 
     if (forgottenPasswordEmail != null && !forgottenPasswordEmail.equals("")) { 
      ForgetPasswordConnection fpc = new ForgetPasswordConnection(); 
      fpc.forgetPasswordConnectionMethod(forgottenPasswordEmail, s, StateMachine.this, f); 
      forgetPasswordSuccess = fpc.abc; 
      if (forgetPasswordSuccess) { 
       showForm("Main", null); 
      } 
     } else { 
     //Dialog.show(null, "Email id is empty", "ok", null); 
//Dialogbox works here, but toastBar doesnt work 
     // f.addShowListener(d -> { 
     // ToastBar.showMessage("Email id is empty", FontImage.MATERIAL_MAIL_OUTLINE, 2000); 
     // });     
     } 
    }); 
    f.add(submit); 
} 

回答

0

注意配置對話框之前,所以你是顯示對話框,而不是父窗體上的toastbar的方法被調用。嘗試保持參考目前的形式,然後添加一個節目聽衆,例如:

parentForm.addShowListener(e -> showMyToastbar()); 
+0

好了,現在我有一個真正的問題。我已經在一個窗體中調用了這個connectionRequest,這個窗體實際上是一個在GUI構建器中創建的空白對話框,這裏addShowListener也沒有辦法。 – beck

+0

我已經更新了上面的問題。看一下 – beck

+1

'ToastBar'不能在'Dialog'上面工作。 –

相關問題