preferably only a cell, but if it is easier to select the entire row, then you can so.
1 answer
In order to decorate the entire row, you need to put down your RowFactory
tableView.setRowFactory((param) -> new ColorRow()); Where
private class ColorRow extends TableRow < myClass > { @Override protected void updateItem(myClass vars, boolean b) { super.updateItem(myClass, b); boolean flag = true; // тут условие, по которому стоит разукрашитьвать строку или нет. if (flag) { this.getStyleClass().add('redRow'); } else { this.getStyleClass().add('greenRow'); } } } In order to decorate any particular cell, you need to override CellFactory
tableView.setCellFactory(param -> new ColorCell()); Where
private class ColorCell extends TableCell < MyClass, String > { @Override protected void updateItem(MyClass myClass, boolean b) { super.updateItem(myClass, b); boolean flag = true; // тут условие, по которому стоит разукрашитьвать ячейку или нет. if (flag) { this.getStyleClass().add('redCell'); } else { this.getStyleClass().add('greenCell'); } } } - I can not optimize for my code, the compiler swears. What to replace "myClass"? - Artes
- On the fact that your table is parameterized - Andrew Bystrov
|