I have tried this but didn\'t work
Column imageColumn = new Column(new ImageCell()) {
@Override
This worked for me:
public class ButtonImageCell extends ButtonCell{
@Override
public void render(com.google.gwt.cell.client.Cell.Context context,
String renderedHtmlStr, SafeHtmlBuilder sb) {
sb.appendHtmlConstant(renderedHtmlStr);
}
}
In a class containing CellTable table
:
TableResources resources = GWT.create(TableResources.class);
ImageResourceRenderer imageRenderer = new ImageResourceRenderer();
...
Column buttonCol = new Column(new ButtonImageCell()) {
@Override
public String getValue(MyRecord record) {
if(record.isOn())
return imageRenderer.render(resources.getOnImg()).asString();
else
return imageRenderer.render(resources.getOffImg()).asString();
}
};
buttonCol.setFieldUpdater(new FieldUpdater() {
public void update(int index, MyRecordobject, String value) {
if (Window.confirm("Do stuff?")) {
//todo: stuff
}
}
});
...
table.addColumn(buttonCol, "");
Where the ImageResource
comes from (resources
):
public interface TableResources extends CellTable.Resources {
interface TableStyle extends CellTable.Style {
}
@Source("/images/on.png")
ImageResource getOnImg();
@Source("/images/off.png")
ImageResource getOffImg();
}