How does one easily apply custom (reusable) cellFactories to javafx.scene.control.TableCell; or javafx.scene.control.TableView;?
How does one easily apply custom (reusable) cellFactories to javafx.scene.control.TableCell; or javafx.scene.control.TableView; ?
Share
To apply custom CellFactories which format the displayed text within a cell, its color and so on, the following example might be good help.
Initial situation
Let’s assume you have a Bean/POJO
Person:Where
levelOfGrowthis the percent-value of how much the growth of a person has been completed.It might be set between 0.00 to 1.00.
Lets also assume you have created your view inside a FXML which is bound to a controller
MainWindowController. You also set the column to display thelevelOfGrowthto the idlevelOfGrowthColumnThe intention
The problem in above example is that the values shown in the view are like 0.5 instead of 50%. We also might like to change the color of values like 100% to green.
The solution
What we need is one (reusable) class that describes how the double-values have to be formatted/printed in the view and to connect that class with the
levelOfGrowthColumn.The ‘formatter’-class
Use it within your controller