By "screens" you mean JavaFX Stage instances, right? If so, it is rather simple:
- Load the 2nd fxml file
- Acquire the controller instance via the FXML loader
- Pass the "parameter" by calling a setter method on the controller.
The only somewhat unusual thing is the acquiring of the controller reference. You need to create an instance of FXMLoader. It does not work with the usually called static methods:
(Main Class of the app)
public class MyFXMLApp extends Application {
@Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("MainForm.fxml"));
Parent root = (Parent) loader.load();
// as soon as the load() method has been invoked, the scene graph and the
// controller instance are availlable:
MainFormController controller = loader.getController();
controller.setText("Ready.");
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
// ...
(The controller)
public class MainFormController implements Initializable {
// some ui control:
@FXML
private Label label;
// JavaFX property for values that shall be accessible from outside:
private final StringProperty text = new SimpleStringProperty();
public String getText() {
return text.get();
}
public void setText(String value) {
text.set(value);
}
public StringProperty textProperty() {
return text;
}
@Override
public void initialize(URL url, ResourceBundle rb) {
System.out.println("MainFormController.initialize");
this.label.textProperty().bind(this.text);
}
// ...
The example uses JavaFX properties for holding the "parameter" in the controller - thus, the value and it's change are easily observable and the property may be bound to any other string property.