title: Populating table data with javafx using fxml
body: <p>It has been so difficult for me to try and get an answer for this.  Oracle doesn't document on their website for some reason?!  It has been asked on stackoverflow already (<a href="https://stackoverflow.com/questions/17384577/javafx-tableviewfxml-filling-with-data">JavaFX: TableView(fxml) filling with data</a>, and <a href="https://stackoverflow.com/questions/20074396/javafx-fxml-table-why-wont-my-data-display">JavaFX FXML table; why won&#39;t my data display</a>), but when i try to recreate with the answers given, I am still unable to get it to work.  I would be extremely grateful if someone would be able to help!  I'll give out all the code of have put together.  </p>
  
  <pre><code>public class Heroes extends Application {
  
      public static void main(String[] args) {
          launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          try {
              AnchorPane page = FXMLLoader.load(Heroes.class.getResource("FXMLDocument.fxml"));
  
              Scene scene = new Scene(page);
              primaryStage.setScene(scene);
              primaryStage.setTitle("Sample Window"); 
              primaryStage.setResizable(false); 
              primaryStage.show();
          } catch (Exception e) {
          }
      }
  }
  
  public class FXMLDocumentController implements Initializable {
  
      /**
       * Initializes the controller class.
       */
      @FXML
      TableView&lt;Table&gt; tableID;
      @FXML
      TableColumn&lt;Table, Integer&gt; tID;
      @FXML
      TableColumn&lt;Table, String&gt; tName;
      @FXML
      TableColumn&lt;Table, String&gt; tDate;
      @FXML
      TableColumn&lt;Table, String&gt; tPrice;
      int iNumber = 1;
      ObservableList&lt;Table&gt; data =
              FXCollections.observableArrayList(
              new Table(iNumber++, "Superman", "12/02/2013", "20"),
              new Table(iNumber++, "Batman", "2/02/2013", "40"),
              new Table(iNumber++, "Aquaman", "1/02/2013", "100"),
              new Table(iNumber++, "The Flash", "12/02/2013", "16"));
  
      @Override
      public void initialize(URL url, ResourceBundle rb) {
          // System.out.println("called");
  
          tID.setCellValueFactory(new PropertyValueFactory&lt;Table, Integer&gt;("rID"));
          tName.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rName"));
          tDate.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rDate"));
          tPrice.setCellValueFactory(new PropertyValueFactory&lt;Table, String&gt;("rPrice"));
          tableID.setItems(data);
  
      }
  }
  
  public class Table {
  
      SimpleIntegerProperty rID;
      SimpleStringProperty rName;
      SimpleStringProperty rDate;
      SimpleStringProperty rPrice;
  
      public Table(int rID, String rName, String rDate, String rPrice) {
          this.rID = new SimpleIntegerProperty(rID);
          this.rName = new SimpleStringProperty(rName);
          this.rDate = new SimpleStringProperty(rDate);
          this.rPrice = new SimpleStringProperty(rPrice);
          System.out.println(rID);
          System.out.println(rName);
          System.out.println(rDate);
          System.out.println(rPrice);
      } 
  
      public Integer getrID() {
          return rID.get();
      }
  
      public void setrID(Integer v) {
          this.rID.set(v);
      }
  
      public String getrDate() {
          return rDate.get();
      }
  
      public void setrDate(String d) {
          this.rDate.set(d);
      }
  
      public String getrName() {
          return rName.get();
      }
  
      public void setrName(String n) {
           this.rDate.set(n);
      }
  
      public String getrPrice() {
          return rPrice.get();
      }
  
      public void setrPrice(String p) {
         this.rPrice.set(p); 
      }
  }
  </code></pre>
  
  
  
  <pre><code>&lt;AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="heroes.FXMLDocumentController"&gt;
    &lt;children&gt;
      &lt;SplitPane dividerPositions="0.535175879396985" focusTraversable="true" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
        &lt;items&gt;
          &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"&gt;
            &lt;children&gt;
              &lt;TableView fx:id="tableID" prefHeight="210.0" prefWidth="598.0" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"&gt;
                &lt;columns&gt;
                  &lt;TableColumn minWidth="20.0" prefWidth="40.0" text="ID" fx:id="tID" &gt;
                      &lt;cellValueFactory&gt;
                         &lt;PropertyValueFactory property="tID" /&gt;
                       &lt;/cellValueFactory&gt;
                  &lt;/TableColumn&gt;
                  &lt;TableColumn prefWidth="100.0" text="Date" fx:id="tDate" &gt;
                      &lt;cellValueFactory&gt;
                         &lt;PropertyValueFactory property="tDate" /&gt;
                      &lt;/cellValueFactory&gt;
                   &lt;/TableColumn&gt;
                  &lt;TableColumn prefWidth="200.0" text="Name" fx:id="tName" &gt;
                      &lt;cellValueFactory&gt;
                         &lt;PropertyValueFactory property="tName" /&gt;
                       &lt;/cellValueFactory&gt;
                  &lt;/TableColumn&gt;
                  &lt;TableColumn prefWidth="75.0" text="Price" fx:id="tPrice" &gt;
                       &lt;cellValueFactory&gt;
                         &lt;PropertyValueFactory property="tPrice" /&gt;
                       &lt;/cellValueFactory&gt;
                  &lt;/TableColumn&gt;
                &lt;/columns&gt;
              &lt;/TableView&gt;
            &lt;/children&gt;
          &lt;/AnchorPane&gt;
          &lt;AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" /&gt;
        &lt;/items&gt;
      &lt;/SplitPane&gt;
    &lt;/children&gt;
  &lt;/AnchorPane&gt;
  </code></pre>