How to add image to cell in cellTable in GWT

I want to add an image to a cell in 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, now the table has an empty column and there is no image in it. Am I something wrong here? Any suggestion is welcome. Thanks.

+4
source share
3 answers

Use 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(); } }; 
+16
source
 Column<Contact, String> imageColumn = new Column<Contact, String>( new ClickableTextCell() { public void render(Context context, SafeHtml value, SafeHtmlBuilder sb) { sb.appendHtmlConstant("<img width=\"20\" src=\"images/" + value.asString() + "\">"); } }) { @Override public String getValue(Contact object) { return "contact.jpg"; } }; table.addColumn(imageColumn, ""); 
+8
source

I assume the error in the message is IonuΕ£ G. Stan

i, suppose that

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

so with public ImageResource getValue and not public String getValue

+5
source

All Articles