0

I am new to JavaFX and I don't know how to set cell styles dynamically in a TreeTableView.

For example, I wish to set a cell's background color on the fly based on user input. The user may specify a range (e.g. dark red to light red). I would calculate the appropriate value for a specific cell and then set the background color based on the calculation result.

I am familiar with JTable's approach of writing a cell renderer but JavaFX appears to handle things quite differently.

khow
  • 21
  • 2
  • 1
    Research `CellFactory`. I dont know anything about `JTable`, but based on the words "cell renderer", that is what a `cell factory` is for JavaFX`. – Hypnic Jerk Dec 21 '18 at 19:48
  • 1
    Maybe try one of the `TreeTableCell` subclasses seen [here](https://stackoverflow.com/search?q=%5Bjavafx%5D+TreeTableView+setCellFactory). – trashgod Dec 22 '18 at 12:58
  • 1
    Check out the [Oracle Tutorial](https://docs.oracle.com/javafx/2/ui_controls/tree-view.htm) on the `TreeView` class. It also explains how to create a custom `CellFactory`. – Zephyr Dec 22 '18 at 16:10
  • Thanks for all your suggestions. I was able to achieve what I wanted by using a CellFactory and overriding the updateItem() method of the TreeTableCell that the CellFactory returned. – khow Dec 24 '18 at 14:58

0 Answers0