ToastBar
当我在代码的任何部分中使用它时,它都能正常工作,但是当我使用它显示一些消息时,即连接已完成。在postResponse
的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);
更新1:
它是在Gui生成器中创建的空白对话框。 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);
}
最佳答案
请注意,在处理对话框之前会调用该方法,因此您将在对话框上显示Toastbar,而不是父窗体。尝试保留对当前表单的引用,然后向该表单添加显示监听器,例如:
parentForm.addShowListener(e -> showMyToastbar());