-2

As per my thinking When the below two lines are executed by Compiler in javaFX, First line just set the location of ABC.fxml file. And in second line when execute loader.load() that time Compiler make one object of the Controller of ABC.fxml file and which is ABCcontroller.java. and call it.

  loader.setLocation(MyApplicationClass.class.getResource("/demo/view/ABC.fxml"));
  rootDisplay = (BorderPane) loader.load();

During this time(at loader.load()) I want to pass the stage value from my current class file(mainclass.java) to the this object of ABCcontroller.class. Because i need this value further.

I have seen like

loader.load(URL Location, ResourceBundle resources,.....)

Can we pass the value of stage by giving the Parameter. I do not not how to call this or what is the use of this parameters.

Please suggest me how to implement in this way or another idea to do this same thing.

DVarga
  • 21,311
  • 6
  • 55
  • 60
Vimal
  • 11
  • 3
  • *"During this time (at `loader.load()`) I want to pass the stage..."*. Do you really need it to happen *at that time*, or can it happen after `load` has returned? The duplicate question shows you how to pass values to the controller after `load` has completed. – James_D Jun 03 '16 at 13:01

1 Answers1

0

You can do the following to pass over a parameter to another controller:

Create a method in your controller class that accepts the parameter, for example:

public void initVariables(String variable) {
    this.variable = variable;
}

call the method after the loader.load():

WindowController controller = fxmlLoader.<WindowController>getController();
controller.initVariables("Test");

Replace WindowController with the name of your controller class.

Moh-Aw
  • 2,976
  • 2
  • 30
  • 44