0

Let's say I have a controller class for View1.fxml looking like this:

public class Controller1 {

    @FXML
    public TextField firstName;
    @FXML
    public TextField lastName;

    public void findPerson(ActionEvent event) throws IOException {
        Stage stage = new Stage();
        FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource("View2.fxml"));
        stage.setScene(new Scene((Pane) loader.load()));
        stage.show();
    }

As you can see, I have two text fields for person's first and last name and I'm trying to open second window where I'll be able to find some person (e.g in some database). But let's assume a controller class for the second window looks like this:

public class Controller2 {

  public String fName;
  public String lName;

  public void setData() {
      fName = "John";
      lName = "Smith";
}

In Controller2 I'm setting values for String variables fName and lName and I would like to set those values in firstName and lastName text fields without opening the View1.fxml again. Does anyone know how to do that?

I was looking for an answer here on Stack Overflow but there were only problems with passing parameters from first window to the second, not vice versa.

beresfordt
  • 5,088
  • 10
  • 35
  • 43
ka.e
  • 1
  • 2
  • See http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml – Darth Ninja Nov 21 '15 at 22:09
  • http://stackoverflow.com/questions/28946651/javafx-pass-parameter-and-values-from-one-controller-to-another is similar (though a little more complex). See if it helps. – James_D Nov 21 '15 at 23:06

0 Answers0