Questions on image cell showing images, please help

684 views
Skip to first unread message

Hong

unread,
Mar 20, 2011, 7:19:06 AM3/20/11
to Google Web Toolkit
Hi, everyone

I tried to put some images in gwt cell table where I used image cells
to do this. But those images turned out pretty large in the webpage. I
tried to use "aCellTable.setColumnWidth(column, width)", but it didn't
help. I know if only to display a single image, I can say "String url
= anImageResource.getUrl(); Image aImage = new Image(url);
aImage.setPixelSize(x,y);" things like that. But how can I scale an
image in a image cell / cell table?

Some of my codes:

CellTable<VehicleInfo> vehicleCellTable = new
CellTable<VehicleInfo>(1);

.....

Column<VehicleInfo,String> imageColumn = new
Column<VehicleInfo,String>(new ImageCell())
{

@Override
public String getValue(VehicleInfo object) {

return object.imageUrl;
}

};

vehicleCellTable.addColumn(imageColumn,"Image");

vehicleCellTable.setColumnWidth(imageColumn, "3em"); //doesn't help

.....

Alexandre Ardhuin

unread,
Mar 23, 2011, 4:42:26 PM3/23/11
to google-we...@googlegroups.com
Hi,

If you have ImageResource, you can use com.google.gwt.cell.client.ImageResourceCell .
If you have only urls, you can create your own ImageCell like com.google.gwt.cell.client.ImageCell and change html template used :


public class MyImageCell extends AbstractCell<String> {
  interface Template extends SafeHtmlTemplates {
    @Template("<img src=\"{0}\" style=\"width:20px;height:20px;\"/>")  // 20*20 size
    SafeHtml img(String url);
  }

  private static Template template;

  /**
   * Construct a new MyImageCell.
   */
  public MyImageCell() {
    if (template == null) {
      template = GWT.create(Template.class);
    }
  }

  @Override
  public void render(Context context, String value, SafeHtmlBuilder sb) {
    if (value != null) {
      // The template will sanitize the URI.
      sb.append(template.img(value));
    }
  }
}


Alexandre.




2011/3/20 Hong <maho...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Reply all
Reply to author
Forward
0 new messages