GWT TableCellElement未显示背景图像

GWT TableCellElement未显示背景图像,gwt,Gwt,我使用gwt来显示表格单元格中的图像,它是一个动态图像,所以我不需要硬编码,但它不显示其中的实际图像。这是我的密码 我的UiBinder是这样的: <table> <tr><td ui:field="tableCellElement"/></tr> </table> 代码执行成功,但没有显示图像,我目前正在使用IE9,但我也在IE8和IE7上尝试过 我知道它可以用css解决,但这里我们的图像是动态的,所以

我使用gwt来显示表格单元格中的图像,它是一个动态图像,所以我不需要硬编码,但它不显示其中的实际图像。这是我的密码

我的UiBinder是这样的:

    <table>
       <tr><td ui:field="tableCellElement"/></tr>
    </table>
代码执行成功,但没有显示图像,我目前正在使用IE9,但我也在IE8和IE7上尝试过

我知道它可以用css解决,但这里我们的图像是动态的,所以如果我们有100个图像,我不能为每个图像定义100个css


如果有人能帮我解决这个问题,我真的很感激

您的代码基本正常。您看不到图像的原因可能只是td的默认大小为0

背景图像不会影响元素的大小,因此需要手动设置。如果所有图像的大小相同,可以在UiBinder中设置一次:


.myTableCell{
宽度:32px;
高度:32px;
}
...
否则,以编程方式进行设置:

Style=tableCellElement.getStyle();
style.setBackgroundImage(“url(“+”patternImage.getUrl()+”)”;
style.setWidth(patternImage.getWidth(),Unit.PX);
style.setHeight(patternImage.getHeight(),Unit.PX);

发布UI活页夹模板的所有者类。我为UiField TableCellElement使用了
com.google.gwt.dom.client.TableCellElement
类。但是我发现
TableCellElement
没有定义
setBackgroundImage
    void someMethod(Image patterImage) {
        tableCellElement.setBackgroundImage("url('"+patternImage.getUrl()+"')");
        // and I have tried this without using url as well but it doesn't work
        // DOM.setstyleattribute also doesn't work...
    }