我试图通过单击该按钮来更改标签的文本。所以我使用setText进行更改,然后调用revalidate(),但是当我运行它并按下按钮时,文本在标签中不会更改。这是我的代码。 我在做什么错?Codename one。使用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语句下添加了代码,以防其他情况未被调用。仍然没有工作...
输出中没有错误消息。 – Kyri33