In your Messagecontroller Application class, create a reference to your Controller class so you can change and pass objects to it, you can do something like this:
public class Principal extends Application {
//Criando um atributo para acessar o Controller da aplicação
public static PrincipalController controller ;
@Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource(this.getClass().getSimpleName() + ".fxml"));
Parent root = (Parent) loader.load();
this.controller = (PrincipalController) loader.getController();
Scene scene = new Scene(root)
stage.setScene(scene);
stage.show();
}
Then, in your Controller class, create an attribute to receive the object you want to change. In your case it would be a String to change the Label.
private String usuarioLogado
In the Login Controller, after checking the user credentials, please enter the Messagecontroller class the desired variable, and seven its value:
@FXML
private void actionBtnLogar(ActionEvent event) {
//....
try {
usuario = this.verificaCredencias(login, senha);
if (usuario) {
Principal prin = new Principal ();
prin.start(new Stage());
prin.controller.setUsuarioLogado("usuario");
Login.fechar();
} else {
//tratar
}
} catch (Exception ex) {
//tratar
}
}
Finally, create a function in the Messagecontroller class to change the desired label. This function must be executed after the Controller class initialize method.
I hope I’ve helped.
What is your code? What error appears? Without this information it will be difficult for anyone to give a good answer
– Denis Rudnei de Souza
I edited it. I’m sorry.
– Rodrigo Albuquerque
No problem, no need to apologize
– Denis Rudnei de Souza