1

I have a tableview tbvAlumnos which two tablecolumns: tbcNombre, tbcApellidos.

I mapped a list from pojo:

public class Alumno
{
  private boolean activo;
  private String nombre;
  private String apellidos;
}

Where I mapped alumnos's list to tableview I want to text fill row with red colour where alumno activo is false and text fill row with green when is true.

I tried but I don't know how to get each alumno to check if is active or not because follow code fails because I pass Alumno item rather than String.

    tbcNombre.setCellFactory(column -> {
        return new TableCell<Alumno, Alumno>() {
            @Override
            protected void updateItem(Alumno item, boolean empty) {
                super.updateItem(item, empty);

                if (item == null || empty) {
                    setText(null);
                    setStyle("");
                } else {
                    // Format date.
                    setText(item.toString());
                    setStyle("-fx-text-fill: red");
                }
            }
        };
    });

So How can I add style to all row fields based on condition of each item of each row.

Marcos
  • 4,827
  • 3
  • 20
  • 28
  • Use a [`rowFactory`](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableView.html#rowFactoryProperty) for this, instead of a cell factory. [This question](http://stackoverflow.com/questions/20350099/programmatically-change-the-tableview-row-appearance/20475137#20475137) is similar (actually quite a bit more complex) but it should be enough for you to do what you need. – James_D Mar 04 '15 at 02:05

0 Answers0