How can I pass a parameter to the controller from Application in the start method?

start method:

public void start(Stage primaryStage) throws Exception { FXMLLoader loader = new FXMLLoader(getClass().getResource("windows/userTestWindow.fxml")); Parent root = loader.load(); UserTestController controller = loader.getController(); controller.setStage(primaryStage); primaryStage.setTitle("TESTOsteron - Тест"); primaryStage.setScene(new Scene(root)); primaryStage.setMaximized(true); primaryStage.setMinWidth(MIN_WIDTH); primaryStage.setMinHeight(MIN_HEIGHT); primaryStage.getIcons().add(icon); //controller.setTestKod(testKod); primaryStage.show(); } 

tried to pass through

  controller.setTestKod(testKod); 

that is, the controller has such a method and the testKod field, but nothing is transmitted, testKod is still 0. I just do not understand why the Stage is then transmitted in this way to the controller, but a simple parameter cannot.

  • Maybe the problem is that you are not updating testKod? In your opinion everything should be right. Only it is not clear why you shove the controller primaryStage - Andrew Bystrov
  • to control the scene from the controller - asix_leon
  • @AndrewBystrov you were right. It was necessary to re-initialize FXML after changing the parameter. So everything worked - asix_leon

0