我是Vaadin的新手,但确实有一些Java Swing经验。

我正在尝试使用table.setCellStyleGenerator设置标题为“名称”的特定单元格的颜色。

我正在研究vaadin书中的一个示例:

Table table = new Table("Table with Cell Styles");
    table.addStyleName("checkerboard");

    table.addContainerProperty("0",String.class,null,"Name", null,  null);
    table.addContainerProperty("1",String.class,null,"Surname", null,  null);
    table.addContainerProperty("2",Date.class,null,"Date.", null,  null);
    table.addContainerProperty("3",Integer.class,null,"Required.", null,  null);
    table.addContainerProperty("4",Integer.class,null,"Complete", null,  null);


    table.addContainerProperty("5",String.class,null,"Cakes", null,  null);
    table.addContainerProperty("6",Integer.class,null,"Cake Quantity", null,  null);
    table.addContainerProperty("7",String.class,null,"Status", null,  null);
    table.addContainerProperty("8",TextField.class,null,"Notes", null,  null);


我已按如下方式填充表格:

/* Add a few items in the table. */
    table.addItem(new Object[] {
        "Nicolaus","Copernicus",new Date("21/05/2011"), new Integer(1473), new Integer(1), "Cake",  new Integer(1473), "cakestatus", commentsField }, new Integer(3));


我可以与样式表进行交流,但是当我尝试以下操作时:

table.setCellStyleGenerator(new Table.CellStyleGenerator() {
        public String getStyle(Object itemId, Object propertyId) {
            int row = ((Integer)itemId).intValue();
          int col = Integer.parseInt((String)propertyId);


         System.out.println("COL:"+ col);
            // The first column.
          if (col == 0)
             return "rowheader";
                                  ....


[b] PropertyId [/ b]出现为空。

Tomcat产生了以下内容:


  严重:终端错误:
  java.lang.NumberFormatException:空
      在java.lang.Integer.parseInt(未知来源)


我敢肯定我会犯一些新手错误。

顺便说一下,我的styles.css的访问方式如下:

mainWindow.setTheme("colouredCells");

/* Create the table with a caption. */
Table table = new Table("Table with Cell Styles");
table.addStyleName("checkerboard");


并且CSS包含以下内容:

@import url(../colouredCells/styles.css);
/* Using the old default theme (runo) as the basis for now */





/* Center the text in header. */
.v-table-header-cell {
    text-align: center;
}

/* Basic style for all cells. */
.v-table-checkerboard .v-table-cell-content {
    text-align: center;
    vertical-align: middle;
    padding-top: 12px;
    width: 20px;
    height: 28px;
}

/* Style specifically for the row header cells. */
.v-table-cell-content-rowheader {
    background: #E7EDF3
     url(../default/table/img/header-bg.png) repeat-x scroll 0 0;
}

/* Style specifically for the "white" cells. */
.v-table-cell-content-white {
    background: white;
    color: black;
}

/* Style specifically for the "black" cells. */
.v-table-cell-content-black {
    background: #60497b;
    color: white;
}

最佳答案

propertyId为null的原因已在CellStyleGenerator的javadoc中进行了解释:单元格样式生成器也被调用以为每行可选地设置样式,在这种情况下,propertyId为null。如果propertyId为null,则可能只想返回null。

07-22 02:26