The approach from the previous section will not work if you need to have certain data accessible at the time of the initialize() call. If the controller is set by the fx:controller attribute in FXML, it will be constructed automatically by JavaFX.
For such cases, there is an option to use a preconstructed controller:
public class PreconstructedController implements Initializable { private final String newText; public PreconstructedController(String newText) { this.newText = newText; } @FXML private Button button; @FXML private TextField textField; @Override public void initialize(URL url, ResourceBundle rb) { button.setText(newText); } }
Also, you need to remove the fx:controller attribute from the FXML ...