title: How do I make a generic TableColumn renderer for JavaFX TableView column
body: <p>In a javaFX view controller, initialize method, I have a <code>TableView</code> column renderer that shows financial amounts, with each cell being rendered with an amount and in red or blue color depending on whether the amount is a debit or credit amount. </p>
  
  <pre><code>@Override
    public void initialize(URL url, ResourceBundle rb) 
   budgetAmountCol.setCellValueFactory(cellData -&gt;       cellData.getValue().budgetAmountProperty());
  // Custom rendering of the budget amount cells in the column.
   budgetAmountCol.setCellFactory((TableColumn&lt;TxnObject, String&gt; column) -&gt; {
  return new TableCell&lt;TxnObject, String&gt;() {
      @Override
      protected void updateItem(String item, boolean empty) {
        super.updateItem(item, empty); 
        if (item == null || empty) {
        }
        else {
          double amt = Double.parseDouble(item);
          if (amt == 0) {
            setId("zero-amt");
          } else {
            if (amt &lt; 0){
              item = item.substring(1, item.length());
              setId("debit-amt"); 
            } else {
              setId("credit-amt");               
            }
          }
        }
        setText(item);
      }
    };
  });
  </code></pre>
  
  <p>Because I have several columns that need to be rendered similarily I am trying to avoid copious amounts of source code and turn the above into a single method that can be passed parameters and thus render the columns, something like </p>
  
  <pre><code>private void renderColumn(..) { }
  </code></pre>
  
  <p>The variables that occupy is table cell in the column are defined in an object definition like this:</p>
  
  <pre><code>public class TxnObject {
        ..
        private final StringProperty budgetAmount;
  
      ..
      public String getbudgetAmount() {
          double d = Double.parseDouble(budgetAmount.get());
          setbudgetAmount(MainApp.formatAmount(d));
          return budgetAmount.get();
        }
  
        public void setbudgetAmount(String budgetAmount) {
          this.budgetAmount.set(budgetAmount);
        }
  
        public StringProperty budgetAmountProperty() {
          return budgetAmount;
        }
  </code></pre>
  
  <p>The requirement is therefore to pass the content of the second line of the code, i.e.</p>
  
  <pre><code>budgetAmountCol.setCellValueFactory(cellData -&gt; cellData.getValue().budgetAmountProperty());
  </code></pre>
  
  <p>to render column: So at a minimum the method needs the table column and the variable property:</p>
  
  <pre><code>private void renderColumn(TableColumn&lt;TxnObject, String&gt; tcol, StringProperty sprop) {
      node.setCellValueFactory(..)
  }
  </code></pre>
  
  <p>But I can’t get the correct call to the method. I have tried the following with the indicated result:</p>
  
  <pre><code>renderColumn(budgetAmountCol, budgetAmountProperty());
  syntax error: no method BudgetAmountProperty()
  renderColumn(budgetAmountCol, cellData.getValue().budgetAmountProperty());
  syntax error: Cannot find symbol CellData
  renderColumn(budgetAmountCol, cellData -&gt;    cellData.getValue().budgetAmountProperty());
  syntax error: StringProperty is not a functional interface
  </code></pre>
  
  <p>Im finding the syntax and understanding of how to achieve my object rather challenging and would appreciate if I could get some suggestions to try and achieve a solution.</p>