I can not set the text of the text field. There is no error, but the text box is still empty. The rest of the program works, the method is called, and System.out.println (...) prints the correct text. Therefore, the problem is that the text of the text field cannot be set. Even if I just write textField.setText ("0"); the text box is still empty. When I set the text for a text field under public void initialize (...), it also works. So why doesn't it work in setCurrentInfo?
@FXML
private TextField textField;
private Info currentInfo;
@Override
public void initialize(URL url, ResourceBundle rb) {
}
public void setCurrentInfo(Info currentInfo) {
textField.setText(currentInfo.getpw1());
System.out.println(currentInfo.getpw1());
this.currentInfo = currentInfo;
}
The part of the controller where setCurrentInfo is called:
@FXML
private void handleBtn1(ActionEvent event) throws Exception{
Info info = new Info(textFieldA.getText(), textFieldB.getText());
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("FXMLPassword.fxml"));
loader.load();
Stage stage;
Parent root;
if(event.getSource()==btn1){
stage=(Stage) btn1.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXMLPassword.fxml"));
}
else{
stage=(Stage) btn1.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
FXMLPasswordController passwordController = loader.getController();
passwordController.setCurrentInfo(info);
}
source
share