title: javaFX tableView with Map
body: <p>How to write data in table?<br />
  I have <code>class Database</code> which contains field<code>Long id</code> in database I have <code>Map&lt;Long, Product&gt;</code> where I want to store my products.<br />
  I also have <code>class Product</code> which contains fields <code>String name; BigDecimal price; Category category;//category is Enum</code>.<br />
  And in <code>class Controller</code>:</p>
  <pre><code>    @FXML
      private TableView&lt;Map&gt; tableWithProductsId;
  
      @FXML
      private TableColumn&lt;Map, String&gt; nameColumn;
  
      @FXML
      private TableColumn&lt;Map, Long&gt; productIdColumn;
  
      @FXML
      void initialize() {
          BigDecimal price = new BigDecimal(&quot;0.50&quot;);
          BigDecimal price1 = new BigDecimal(&quot;5.25&quot;);
          BigDecimal price2 = new BigDecimal(&quot;0.79&quot;);
          Product product = new Product(&quot;Apple&quot;, price, Category.FRUIT);
          Product product1 = new Product(&quot;Mango&quot;, price2, Category.FRUIT);
          Product product2 = new Product(&quot;Potatoe&quot;, price1, Category.VEGETABLE);
  
          Database database = new Database();
          database.saveProduct(product);
          database.saveProduct(product1);
          database.saveProduct(product2);
  
          Map&lt;Long, Product&gt; allProductsFromDatabase = database.getAllProducts();
          ObservableList&lt;Map&gt; listOfProducts = FXCollections.observableArrayList(allProductsFromDatabase);
  
          tableWithProductsId.setItems(listOfProducts);
          nameColumn.setCellValueFactory(new MapValueFactory&lt;&gt;(&quot;name&quot;));//this not works
          //how to setCellValueFactory
  </code></pre>
  <p>I tried this link also:<a href="https://docs.oracle.com/javase/9/docs/api/javafx/scene/control/cell/MapValueFactory.html" rel="nofollow noreferrer">docs.oracle.MapValueFactory</a> but this won't work for me.</p>
  <p>I want to achieve something like this: <a href="https://i.stack.imgur.com/7iCPF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7iCPF.png" alt="enter image description here" /></a><br />
  Where <code>productId</code> I can get from <code>class Database;</code> with method <code> getProductId();</code> and other fields I can get from <code>class Product;</code> with methods <code>getProductName();...</code> maybe I need to change my <code>tableView</code> field on <code>@FXML private TableView&lt;Map&lt;Long, Product&gt;&gt; tableWithProductsId;</code>
  ? and table columns also need to be changed on <code>@FXML private TableColumn&lt;Map&lt;Long, Product&gt;, String&gt; nameColumn;</code>? I don't understand how to do this correctly.</p>