4

I'm trying to change the color of a row on a table based on a hex value for the row item. I'm basically trying to generate the css on the fly similar to generating a cssLayout like this

CssLayout content = new CssLayout( ) {
      @Override
      public String getCss( Component c ) {
        return "background: " + colorCode + ";";
      }
    };

Here's the code I'm using now

    table.setCellStyleGenerator(
    new Table.CellStyleGenerator( ) {
      public String getStyle( Object itemId, Object propertyId ) {
        return  "green";
      }
    } );

But it only works for setting the stylename, so I'd have to have millions of style names to accommodate all the possible hex values for the colors the user wants.

4

2 回答 2

2

您可以使用 CSSInject 插件即时添加所需的样式名称。

请参阅https://vaadin.com/directory#addon/cssinject

String color = "#CCDDFF";
CSSInject css = new CSSInject(getUI());
css.setStyles("."+color+" { background-color: "+color+"; }");
于 2013-05-15T15:00:59.117 回答
0

在现有的 CSS 文件中,您可以将颜色更改定义background-color: #00ff00;为样式“绿色”并考虑您的约束返回绿色样式。看看颜色更改

于 2013-05-14T14:08:31.650 回答