title: JavaFX Textfield data to TableView in different Stage
body: <p>I'm trying to input user data from <code>TextField</code> in new window into <code>TableView</code> in the main window. But it is not populating table, and I'm not getting any Exception. On button clicked new window just closes. I'm creating very simple app just to figure out how to communicate properly between controllers.</p>
  
  <pre><code>package sample;
  
  import javafx.application.Application;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.Parent;
  import javafx.scene.Scene;
  import javafx.stage.Stage;
  
  public class Main extends Application {
      static Stage primaryStage;
      @Override
      public void start(Stage primaryStage) throws Exception{
          Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
          this.primaryStage= primaryStage;
          this.primaryStage.setTitle("Hello World");
          this.primaryStage.setScene(new Scene(root));
          this.primaryStage.show();
      }
  
      public  void closeStage(){
          primaryStage.close();
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>Controller class for main window where are table and button for opening new <code>Stage</code>:</p>
  
  <pre><code>package sample;
  
  import javafx.fxml.FXMLLoader;
  import javafx.fxml.Initializable;
  import javafx.scene.Scene;
  import javafx.fxml.FXML;
  import javafx.scene.control.Button;
  import javafx.scene.control.TableColumn;
  import javafx.scene.control.TableView;
  import javafx.scene.control.cell.PropertyValueFactory;
  import javafx.scene.layout.BorderPane;
  import javafx.stage.Stage;
  import java.io.IOException;
  import java.net.URL;
  import java.util.ResourceBundle;
  
  
  public class Controller implements Initializable {
      @FXML TableView&lt;radnici&gt; tabela;
      @FXML TableColumn&lt;radnici, String&gt; kolona;
      @FXML Button dodajRadnikaDugme;
      @FXML Button closeDugme;
  
      Main main = new Main();
      static Stage stage = new Stage();
      Scene scene;
      BorderPane borderPane;
  
      @Override
      public void initialize(URL location, ResourceBundle resources) {
          kolona.setCellValueFactory(new PropertyValueFactory&lt;radnici, String&gt;("ime"));
      }
  
      public  TableView&lt;radnici&gt; getTabela() {
          return tabela;
      }
  
      public TableColumn&lt;radnici, String&gt; getKolona() {
          return kolona;
      }
  
      //Opening new Stage on button clicked
      public void dodajRadnikaDugemKlik() throws IOException {
          FXMLLoader loader = new FXMLLoader();
          borderPane = new BorderPane();
          loader.setLocation(getClass().getResource("dodajRadnika.fxml"));
          borderPane = loader.load();
          scene = new Scene(borderPane);
          stage.setTitle("Dodaj Radnika");
          stage.setScene(scene);
          stage.showAndWait();
      }
  
      //Closing main window
      public void closeDugmeKlik(){
          main.closeStage();
      }
  
      //Method for closing new window
      public  void CloseStage(){
          stage.close();
      }
  }
  </code></pre>
  
  <p>Controller class for the new Window where are just <code>TextField</code> and Button:</p>
  
  <pre><code>package sample;
  
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.fxml.FXML;
  import javafx.fxml.FXMLLoader;
  import javafx.scene.control.Button;
  import javafx.scene.control.TextField;
  import javafx.scene.layout.BorderPane;
  import java.io.IOException;
  
  public class dodajRadnikaKontroler {
      @FXML TextField upišiRadnika;
      @FXML Button dodajRadnika;
  
      BorderPane borderPane;
  
      public void initialize(){
          System.out.println("učitavanje podataka...");
      }
  
      //Method for adding data on button clicked from TextField into table in main window
      @FXML public void dodajRadnikaKlik() throws IOException {
          FXMLLoader loader = new FXMLLoader();
          loader.setLocation(getClass().getResource("sample.fxml"));
          borderPane = new BorderPane();
          borderPane = loader.load();
          Controller controller = loader.getController();
          ObservableList&lt;radnici&gt; lista = FXCollections.observableArrayList();
          lista.add(new radnici(upišiRadnika.getText()));
          controller.tabela.setItems(lista);
          upišiRadnika.clear();
          controller.CloseStage();
      }
  }
  </code></pre>
  
  <p>Model Class for workers ("radnici"):</p>
  
  <pre><code>package sample;
  
  public class radnici {
      private String ime;
  
      public radnici(String ime) {
          this.ime = ime;
      }
  
      public String getIme() {
          return ime;
      }
  
      public void setIme(String ime) {
          this.ime = ime;
      }
  }
  </code></pre>
  
  <p>Please can someone help me so that I can finally do this properly.</p>