How to change font color of row in Grid vaadin ?

I have a grid with student list. I want to change font color of text. If male the color will green, and female is blue. How can i do it ?
private Grid<String> _tblGrid;
List<String> datalist = new ArrayList<String>();
for (Student stdItem : stdList)
{
boolean gender = GetGender(stdItem.ID);
datalist.add(new String { stdItem.Name });
}
_tblGrid.setItems(datalist);

https://vaadin.com/docs/latest/components/grid#part-name-generator

The data show is “Name” of student, and the color of name follow by gender field. How to cast ?

I don’t understand the question. I would recommend to not pass an String array and use proper Person objects; then you have easy access to that needed properties.

In my example above, the result in Grid show Name of student . It’s ok

But i want to define Gender of student , if Male change color Name is Green, If Female change color Name is Blue

It’s mean the Name show is correct , but the color of Name not appear

That part is clear. That’s why I suggest to use a proper Object so that you can access the gender in the part generator

For example: my Grid only one column and the column like this
Gender
Male
Male
Female
Male

And i used this one, it’s work , but all color of text is green
_tblGrid.addColumn(data → data[0]).setHeader(“Gender”);
_tblGrid.getStyle().set(“color”, “green”);

Now, i try with rendering data in column , but it not working
_tblGrid.setClassNameGenerator(data → data[0].equalsIgnoreCase(“Male”)? “color:green” : “color:blue”);

I use vaadin plugin Version 0.14.3.7

@quirky-zebra any idea ?

damn that’s old. So you have to take a look at this docs - please take a careful look at the source code snippet. https://vaadin.com/docs/v14/ds/components/grid#styling-rows-and-columns

:tired_face:

_tblGrid.setClassNameGenerator(data → {
if (data[0].contentEquals(“Male”))
return “color:green”;
if (data[0].contentEquals(“Female”))
return “color:blue”;
return null;
});

Class name generator is not supposed to return style but class name that you can use vaadin-grid.css

_tblGrid.setClassNameGenerator(data → {
if (data[0].contentEquals(“Male”))
return “green”;
if (data[0].contentEquals(“Female”))
return “blue”;
return null;
});

And in vaadin-grid.css

.green {
color: green;
}
.blue {
color: blue;
}

@yummy-rhino How about class “primary, success, warning, error” in vaadin ? I tried this below and not working also . As i know have those classname in vaadin ?
_tblGrid.setClassNameGenerator(data → {
if (data[0].contentEquals(“Male”))
return “success”;
if (data[0].contentEquals(“Female”))
return “primary”;
return null;
});