title: How to set CellValueFactory to functions of various properties in javafx?
body: <p>I was building a download manager in javafx in the MVC pattern and got into some trouble. I wanted to list the downloads in a TableView with all properties in various columns. </p>
  
  <p>Suppose I have a model like this.</p>
  
  <pre><code>class Download{
      private SimpleObjectProperty&lt;Integer&gt; part1;
      private SimpleObjectProperty&lt;Integer&gt; part2;
  
      public SimpleObjectProperty&lt;Integer&gt; getPart1Property(){
          return part1;
      }
      public SimpleObjectProperty&lt;Integer&gt; getPart2Property(){
          return part2;
      }
  }
  </code></pre>
  
  <p>Now I have javafx GUI set up with a table view like this.</p>
  
  <pre><code>TableView&lt;Download&gt; table=new TableView&lt;Download&gt;();
  table.setItems(.. Observable list of Download objects ...);
  </code></pre>
  
  <p>If I wanted to add a column in the table-view for the value of part1, I could do it like this.</p>
  
  <pre><code> TableColumn&lt;Download,Integer&gt; part1 = new TableColumn&lt;Download,Integer&gt;("Part 1 value");
   part1.setCellValueFactory(
              (TableColumn.CellDataFeatures&lt;Download, Integer&gt; download) -&gt; download.getValue().getPart1Property());
  </code></pre>
  
  <p>Now I need a column in the table view that shows the <strong>sum of the values of part1 and part2</strong>. <strong>How can I achieve this in javafx?</strong></p>
  
  <p>I have read the docs <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html" rel="nofollow noreferrer">here</a> but sadly couldn't find any way I could accomplish this. Any help would be appreciated.</p>