I\'m having some dificulties to change the appearance of some TableView rows. The line should show the text with a stroke and in red. Actually, I can show it in red color bu
How can I update all columns? If you wish to strike-out entire row, i.e. all cells in a row, every other CellValueFactory should have that condition check:
...
if (indice < getTableView().getItems().size())
bean = getTableView().getItems().get(indice);
if (bean != null && bean.isCancelado())
getStyleClass().add("itemCancelado");
...
Or you could implement your callbacks as decorators and have something like this:
public class CellDecorator implements Callback {
private Callback decorated;
public CellDecorator(Callback toDecorate) {
this.decorated = toDecorate;
}
// Override this to do your thing.
public abstract void doStyle(TableCell tableCell);
@Override
public void style(TableCell tableCell) {
// Let the decorated styler do its thing.
decorated.style(tableCell);
// Now we do our thing.
doStyle(cell);
}
}
public class ItemCanceladoCellFactory extends CellDecorator {
public ItemCanceladoCellFactory(Callback toDecorate) {
super(toDecorate);
}
@Override
public void doStyle(TableCell tableCell) {
...
if (bean != null && bean.isCancelado())
getStyleClass().add("itemCancelado");
}
}
...
colunaCodigo.setCellValueFactory(new ItemCanceladoCellFactory(new MultiPropertyValueFactory("produto.id")));
colunaDescricao.setCellValueFactory(new ItemCanceladoCellFactory(new MultiPropertyValueFactory("produto.descricao")));
colunaDescricao.setCellFactory(new ItemCanceladoCellFactory(new ItemCanceladoCellFactory()));
....
This way you don't have to repeat the "canceled" styling code, and you can apply it to entire row. Please note that this is not JavaFX ready code, this is a general idea.