How to create TableView that displays custom cells containing text and graphics?
To display custom content in TableView you create TableColumn and specify cellValueFactory and in needed cellFactory. Let’s assume that data for each row in the table are represented by insdtances Person class:
Say, you want to display the first and last name of a person as text, but you want to show the favorite color as a circle. Displaying columns with text is simple, you just create a new column and provide cellValueFactory that describes how to extract data from Person object. TableColumn knows how to display text:
Displaying a color circle is not that much more complex, we just need to let the TableColumn know that the favoriteColor should be rendered as a graphic of a specific color. This is done defining custom cellFactory for the column. The factory creates a graphic when cell value changes. As before define how to create cell value from Person object using cellValueFactory:
Below is a complete example that will display a table with custom cells: