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);
setStyle("-fx-text-fill: red");
}
}
};
});
So How can I add style to all row fields based on condition of each item of each row.
Aucun commentaire:
Enregistrer un commentaire