将自定义样式附加到GWT单元格表(在本例中为所有单元格)

将自定义样式附加到GWT单元格表(在本例中为所有单元格),gwt,gwt-2.2-celltable,Gwt,Gwt 2.2 Celltable,我有一个案例,我想附加 white-space: nowrap; 我的手机表中每个单元格的样式。目前,它适用于所有表,但最好知道两者都必须适用于特定的CellTable,并且所有CellTables都有自己的CellTables。要覆盖应用于cellTable中所有单元格的此样式,请创建一个新的css文件: /* Incremental changes from CellTable.css */ .cellTableCell { white-space: nowrap; } 然后创建您

我有一个案例,我想附加

white-space: nowrap;
我的手机表中每个单元格的样式。目前,它适用于所有表,但最好知道两者都必须适用于特定的CellTable,并且所有CellTables都有自己的CellTables。要覆盖应用于cellTable中所有单元格的此样式,请创建一个新的css文件:

/* Incremental changes from CellTable.css */ 
.cellTableCell {
  white-space: nowrap;
}
然后创建您自己的CellTable。资源界面:

public interface TableResources extends CellTable.Resources {

    /**
       * The styles applied to the table.
       */
    interface TableStyle extends CellTable.Style {
    }

    @Override
    @Source({ CellTable.Style.DEFAULT_CSS, "MyOwnCellTableStyleSheet.css" })
    TableStyle cellTableStyle();

}
最后,在创建cellTable时,使用允许您指定要使用哪些资源的

CellTable<Object> myCellTable = new CellTable<Object>(15, GWT.create(TableResources.class));
CellTable myCellTable=newcelltable(15,GWT.create(TableResources.class));

关于一个工作示例,请查看GWT SDK中提供的费用示例。

或者您可以用简单的方法来完成:

CellTable<YourObj> yourTable = new CellTable<YourObj>();
yourTable.getElement().getStyle().setWhiteSpace(WhiteSpace.NOWRAP);
CellTable yourTable=newcelltable();
yourTable.getElement().getStyle().setWhiteSpace(WhiteSpace.NOWRAP);

没有css文件,没有奇怪的样板代码。

回答得很好,与我合作得很好,只是在GWT 2.4上,您必须转换到(Resources)GWT.create(TableResources.class)等资源才能工作。感谢您提供的解决方案。我发现它在完全没有TableStyle接口的情况下也可以工作。您只需编写:CellTable.Style cellTableStyle();这在某种程度上减少了样板文件。我在GWT2.6.0上试过了