我試圖通過單擊該按鈕來更改標籤的文本。所以我使用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