Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a font size for particular column in Vaadin Table?

Tags:

vaadin

I have created Table using vaadin.Now i want to set font size for particular column content in that table.Is it possible to set font size for particular column in that table?. If so please give me idea to set the font size.If u can provide me some code snippet.

like image 844
Kumar Avatar asked Jan 23 '23 11:01

Kumar


2 Answers

Yes, with CellStyleGenarators. Check 5.12.2 in the Book of Vaadin. You basically do a

if(propertyId.equals(yourColumnName)) { 
  return "someStyleName";
} 
else {
  return null;
}

inside your Table.CellStyleGenerator() and set the style for your text in css.

like image 72
Jens Jansson Avatar answered Feb 06 '23 04:02

Jens Jansson


using CellStyleGenerator

simpleTable.setCellStyleGenerator(new Table.CellStyleGenerator() {
        @Override
        public String getStyle(Table components, Object itemId, Object columnId) {
            int row = Integer.valueOf((String)itemId);
            if (row%2 == 0)
                return "grey";
            else
                return "white";
        }
        });

ColumnGenerator as it is described in How to get started with Vaadin: Table Styling

public class DescriptionColumnGenerator implements Table.ColumnGenerator {

@Override
public Object generateCell(Table components, Object itemId, Object columnId) {
    int row = Integer.valueOf((String)itemId);
    Property prop = components.getItem(itemId).getItemProperty(columnId);
    Label label = new Label("desc: " + prop.getValue());

    if (row%2 != 0) {
        label.addStyleName("column-description");
        label.addStyleName("column-" + (String) columnId);
    }
    return label;
} }
like image 44
Alex Avatar answered Feb 06 '23 03:02

Alex