这是我的代码不起作用。图像仍然在左上角。
public class MyImage extends Composite{
private Grid panel;
private Image image;
public MyImage(String imageUrl){
image = new Image(imageUrl);
panel = new Grid(3,3);
panel.setSize("150px", "150px");
image.setSize("96px", "96px");
panel.getCellFormatter().setHorizontalAlignment(1, 1, HasHorizontalAlignment.ALIGN_CENTER);
panel.getCellFormatter().setVerticalAlignment(1, 1, HasVerticalAlignment.ALIGN_MIDDLE);
panel.setWidget(1, 1, image);
initWidget(panel);
}
}