I have gone through this similar question but it use Singleton Class. Also other similar question which I found are mainly nested controllers. So I am raising this simple question hoping to get an answer for binding text property of two TextFields which are in different FXML.
I have two textfields in two different fxmls and these are their controller classes:
TextField1Controller.java
public class TextField1Controller implements Initializable{
@FXML
TextField txt1FxId;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
TextField2Controller.java
public class TextField2Controller implements Initializable{
@FXML
TextField txt2FxId;
@Override
public void initialize(URL location, ResourceBundle resources) {
}
}
MainApp.java
public class MainApp extends Application{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage1) throws Exception {
AnchorPane pane1 = FXMLLoader.load(this.getClass().getResource("TextField1.fxml"));
AnchorPane pane2 = FXMLLoader.load(this.getClass().getResource("TextField2.fxml"));
Stage stage2 = new Stage();
stage1.setScene(new Scene(pane1));
stage2.setScene(new Scene(pane2));
stage1.show();
stage2.show();
}
}
How can I bind the text property of those textfields in my MainApp.java so that typing on one textfield prints on the other text field and vice versa?