简体   繁体   English

java gwt图像不可见

[英]java gwt image invisible

I'm trying to fill a CellTable and in one column I would like to display an Image. 我正在尝试填充CellTable,并在一列中显示一个图像。 This image should be displayed for every row except one. 除每行外,每一行均应显示该图像。 Does anyone know how to add something like this? 有谁知道如何添加这样的东西?

This is what I did: 这是我所做的:

Column column = new Column<RowObject, ImageResource>(new ImageResourceCell()) {

    @Override
    public ImageResource getValue(RowObject object) {
        if (showImageFor(object)) {
            return getImageResource();
        } else {
            return null;
        }
    }
};

cellTable.addColumn(column);

In case you don't know how to obtain an ImageResource, check the docs here . 如果您不知道如何获取ImageResource,请在此处查看文档。

Update : If you want to use a custom cell, you should decide whether or not to draw the image in the cell's render method: 更新 :如果要使用自定义单元格,则应决定是否在单元格的render方法中绘制图像:

public class CustomCell extends AbstractCell<ColumnObject> {
    @Override
    public void render(Context context, ColumnObject value, SafeHtmlBuilder sb) {
        if (showImageFor(value)) {
            // Render the image
        }
    }
}

Then you can add the column to your cell like this: 然后,您可以将列添加到您的单元格中,如下所示:

Column column = new Column<RowObject, ColumnObject>(new CustomCell()) {
    @Override
    public ColumnObject getValue(RowObject object) {
        return getColumnObjectFrom(object);
    }
};

cellTable.add(column);

Use ImageCell or ImageResourceCell. 使用ImageCell或ImageResourceCell。 In getValue() you either return null (no image will be shown), or you return a URL/ImageResource. 在getValue()中,您可以返回null(将不显示图像),或者返回URL / ImageResource。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM