I am doing java fx and i got stuck into passing variable into different FXML scene. so on the first scene controller, LoginController is associated with Login.fxml
public class LoginController {
@FXML private TextField username;
@FXML private PasswordField password;
@FXML private Button loginButton;
@FXML private Label labelStatus;
@FXML private void handleLoginButton() throws InterruptedException {
try {
FXMLLoader mainLoad = new FXMLLoader(getClass().getResource("../View/mainscreen.fxml"));
Parent mainRoot = (Parent) mainLoad.load();
Stage stage = new Stage();
stage.setScene(new Scene(mainRoot));
stage.show();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
and when the new scene open i need to set the label based on the username variable that contains the user input. that means we need to pass variables from Login.fxml into mainscreen.fxml through controoler. How do i achieve this ?