TableColumn tc = new TableColumn();
tc.getStyleClass.add(".style in css file")
i set up the tablecolumn with css file. and i want to make each cell has different backgrounds. is there any way to do it?
Example) TableColumn 1~5
TableColumn 1, row 3 has black and
TableColumn 5, row 4 has green ... etc
To change the behavior of specific cells in a
TableView
you need can set thecellFactory
of theTableColumns
. Here's an example:In my example I just set the color based on the index the cell, but you can change that to something a little more meaningful obviously. E.g. the color could be based on the value of the cell.
Create a
cellFactory
that selects the background color based on the column & row index.Example:
Valid CSS color strings are described here: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#typecolor
style.css