how to add an image to a cell in cellTable in GWT

sherry picture sherry · May 5, 2011 · Viewed 13.9k times · Source

I want to add an image in a cell in the CellTable. After reading the documentation, this is what I did,

Column<Contact, String> imageColumn = new Column<Contact, String>(new ImageCell()) {
    @Override
    public String getValue(Contact object) {
        return "contact.jpg";
    }
  };
table.addColumn(imageColumn, "");

Well, there's an empty column in the table now and no image in it. Am I doing something wrong here? Any suggestion is appreciated. Thank you.

Answer

Ionuț G. Stan picture Ionuț G. Stan · Jul 19, 2011

Use an ImageResourceCell:

interface Resources extends ClientBundle {
  @Source("image-path.png")
  ImageResource getImageResource();
}

Resources resources = GWT.create(Resources.class);

Column<Contact, ImageResource> imageColumn =
  new Column<Contact, ImageResource>(new ImageResourceCell()) {
    @Override
    public ImageResource getValue(Contact object) {
      return resources.getImageResource();
    }
  };