代号一。使用 revalidate() 动态更改标签的文本不起作用

Codename one. Changing a label's text dynamically using revalidate() is not working

我正在尝试通过单击按钮来更改标签的文本。所以我使用 setText 更改它,然后我调用 revalidate() 但是当我 运行 它并按下按钮时,标签中的文本不会改变。这是我的代码。 我做错了什么???

public void setUpSignUpDialog() {
    final Dialog signUpDialog = (Dialog) u.createContainer(theme, "SignUpDialog");
    signUpDialog.setDisposeWhenPointerOutOfBounds(true);
    signUpDialog.setTransitionInAnimator(CommonTransitions.createDialogPulsate());
    signUpDialog.setTransitionOutAnimator(CommonTransitions.createDialogPulsate());
    signUpDialog.showPacked(BorderLayout.CENTER, true);

    final TextField emailField;
    TextField passwordField;
    TextField repeatPasswordField;
    Button registerButton;
    final Label errorLabel;

    emailField = (TextField) u.findByName("EmailField", signUpDialog);
    passwordField = (TextField) u.findByName("passwordField", signUpDialog);
    repeatPasswordField = (TextField) u.findByName("RepeatPasswordField", signUpDialog);
    registerButton = (Button) u.findByName("SignUpButton", signUpDialog);
    errorLabel = (Label) u.findByName("ErrorLabel", signUpDialog);

    registerButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent evt) {
            if (checkEmailField(emailField.getText())) {

            } else {
                errorLabel.setText("Please enter a valid email address");
                errorLabel.getStyle().setFgColor(ColorUtil.CYAN);
                signUpDialog.animate();
            }
            errorLabel.setText("Please enter a valid email address");
            errorLabel.getStyle().setFgColor(ColorUtil.CYAN);
            signUpDialog.revalidate();
        }
    });
}

添加了 signUpDialog 的全部代码。我在 if 语句下添加了代码,以防 else 没有被调用。仍然无法正常工作...

应该可以 输出中有错误信息吗? 你能 post 这个 signupDialog 的全部代码吗?

通过在日志中打印一些文本来检查是否真的调用了该语句的 else 部分。

尝试:

errorLabel.getParent().revalidate();
//OR
errorLabel.getParent().repaint();

替换此代码signUpDialog.showPacked(BorderLayout.CENTER, true); 用 signupDilaog.show();它将起作用

public void setUpSignUpDialog() {
    final Dialog signUpDialog = (Dialog) u.createContainer(theme, "SignUpDialog");
    signUpDialog.setDisposeWhenPointerOutOfBounds(true);
    signUpDialog.setTransitionInAnimator(CommonTransitions.createDialogPulsate());
    signUpDialog.setTransitionOutAnimator(CommonTransitions.createDialogPulsate());
  //  signUpDialog.showPacked(BorderLayout.CENTER, true);

    final TextField emailField;
    TextField passwordField;
    TextField repeatPasswordField;
    Button registerButton;
    final Label errorLabel;

    emailField = (TextField) u.findByName("EmailField", signUpDialog);
    passwordField = (TextField) u.findByName("passwordField", signUpDialog);
    repeatPasswordField = (TextField) u.findByName("RepeatPasswordField", signUpDialog);
    registerButton = (Button) u.findByName("SignUpButton", signUpDialog);
    errorLabel = (Label) u.findByName("ErrorLabel", signUpDialog);

    registerButton.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent evt) {
            if (checkEmailField(emailField.getText())) {

            } else {
                errorLabel.setText("Please enter a valid email address");
                errorLabel.getStyle().setFgColor(ColorUtil.CYAN);
                signUpDialog.animate();
            }
            errorLabel.setText("Please enter a valid email address");
            errorLabel.getStyle().setFgColor(ColorUtil.CYAN);
            signUpDialog.revalidate();
        }
    });
signUpDialog.show();
}