A simple question but I cannot find an answer. I have one FXML file that I would like to instantiate multiple times. Each copy would need it's own handle so I could change data therein. Hypothetically, this is exactly like using the "new" keyword on a class you just created.
In my attempts so far, I have been able to create multiple copies of the fxml file, but there is only one controller, so calling methods means the changes happen to all the copies.
Do I have to create a new controller for every copy of the same fxml file?
Thanks In advance
EDIT
The code I am working this idea out on is here:
JavaFX : Pass parameters while instantiating controller class
Just in case some background may help:
I have a scene that I want to hold multiple instances of a FXML file I made. Setting one FXML file in the scene is easy, but creating multiple (10-20) means I would have 10 to 20 controllers and 10 to 20 instances of the FXML file. Is there a cleaner way to do this?
My hope was to do something like this:
public class SampleController implements Initializable {
@FXML
Label firstName;
@FXML
Label lastName;
public SampleController(Label firstname, Label lastname) {
this.firstName = firstname;
this.lastName = lastname;
}
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
Then call something like:
SampleController Row1 = new SampleController("my", "name");
and have this command load the attached FXML file to the scene along with the data I passed it. But this does not work, it crashes with an exception.