title: Javafx: How to populate a TableView with a map?
body: <p>I'm having trouble trying to populate a TableView with a map&lt;String, Double&gt;. I've been looking at different kind of questions on stack overflow and other pages as well, but my brain doesn't seem to get it.</p>
  <p>I have a class that holds a Map with product names as key, and normal prices as value. I've created a tableView with a column for names and a main column for prices divided in two columns normal and new, as you can see below.</p>
  <pre><code>public class CreatePricesPane extends GridPane {
      private TableView table = new TableView&lt;&gt;();
      private PriceList tempPriceList;
  
  
      public CreatePricesPane(){
          this.tempPriceList = Controller.getController().createPriceList();
          this.setPadding(new Insets(20));
          this.setHgap(70);
          this.setVgap(10);
          this.setGridLinesVisible(false);
  //        this.setPrefSize(800, 500);
          this.setStyle(&quot;-fx-background-color: #fff&quot;);
  
          //All about table
          this.table.setEditable(true);
          this.table.setItems(this.generateData());
          TableColumn&lt;Map,String&gt; nameColumn = new TableColumn(&quot;Names&quot;);
          nameColumn.setMinWidth(300);
  
          TableColumn pricesColumn = new TableColumn(&quot;Prices&quot;);
  
          TableColumn&lt;Map,Double&gt; normalPriceColumn = new TableColumn(&quot;Normal price&quot;);
          normalPriceColumn.setMinWidth(150);
  //        normalPriceColumn.setCellValueFactory(new MapValueFactory&lt;&gt;());
  
          TableColumn newPriceColumn = new TableColumn(&quot;New price&quot;);
          newPriceColumn.setMinWidth(150);
  
          pricesColumn.getColumns().addAll(normalPriceColumn,newPriceColumn);
  
  
          table.setEditable(true);
          table.getSelectionModel().setCellSelectionEnabled(true);
          table.getColumns().setAll(nameColumn, pricesColumn);
  </code></pre>
  <p>I've made this method to make the Map into a ObservableList.</p>
  <pre><code>    private ObservableList&lt;Map&lt;String, Double&gt;&gt; generateData(){
          ObservableList&lt;Map&lt;String,Double&gt;&gt; alldata = FXCollections.observableArrayList();
  
          Map&lt;String, Double&gt; map = new HashMap(this.tempPriceList.getPriceListMap());
  
          for (Map.Entry&lt;String, Double&gt; entry : map.entrySet()) {
              Map&lt;String, Double&gt; dataRow = new HashMap&lt;&gt;();
              dataRow.put(entry.getKey(), entry.getValue());
              alldata.add(dataRow);
          }
          return alldata;
      }
  </code></pre>
  <p>This is where I am stuck. I don't know how to populate each cell with this ObservableList. I do know I have to use &quot;setCellFactory&quot; in some way. Does anyone have any suggestions how to make the last code? Or send me in the right direction?</p>
  <p>Thanks in advance!</p>
  <p>This is what I have tried until now. But actually I'm having trouble understanding what's going on in this code beneath. I hoped it would populate the table with names at start. No luck.</p>
  <pre><code>        Callback&lt;TableColumn&lt;Map, String&gt;, TableCell&lt;Map, String&gt;&gt;
                  cellFactoryForMap = new Callback&lt;TableColumn&lt;Map, String&gt;,
                  TableCell&lt;Map, String&gt;&gt;() {
              @Override
              public TableCell call(TableColumn p) {
                  return new TextFieldTableCell(new StringConverter() {
                      @Override
                      public String toString(Object t) {
                          return t.toString();
                      }
                      @Override
                      public Object fromString(String string) {
                          return string;
                      }
                  });
              }
          };
  
  nameColumn.setCellFactory(cellFactoryForMap);
  </code></pre>