开发者

How to Use GXT Button.setIcon / AbstractImagePrototype

I am trying to extends the AbstractImagePrototype as below:

public class DynamicImagePrototype extends AbstractImagePrototype { private String imagePath = null;

public DynamicImagePrototype (String imagePath) {
    this.imagePath = imagePath;
}

@Override
public void applyTo(Image image) 
{

}

@Override
public Image createImage() {
    // TODO Auto-generated method stub
    Image image = new Image(imagePath);

    return image;
}

@Override
public String getHTML() {
    return null;
}

}

I used it as below:

item = new Button() DynamicImagePrototype image = new DynamicImagePrototype("C:/temp/icons/reporting.g开发者_开发知识库if"); item.setIcon(image);

However, it throw an exception.

My goal is that given an image file name, I want to return an AbstractImagePrototype so I can pass to Button.setIcon();

Thank you greatly for help!


Your class should be like this:

public interface ReefDesktopIconShortcuts extends ClientBundle {

public static final ReefDesktopIconShortcuts INSTANCE = (ReefDesktopIconShortcuts) GWT.create(ReefDesktopIconShortcuts.class);

public ImageResource anImage();
}

Just call this line:

yourBtn.setIcon(AbstractImagePrototype.create(ReefDesktopIconShortcuts.INSTANCE.anImage()));


So far, I have not found an answer for getting the AbstractImagePrototype dynamically yet. I have to use static deferred binding as below:

public interface ReefDesktopIconsShortcuts
extends ImageBundle
{
   AbstractImagePrototype anImage();
}

In the directory where this interface resides, I have an image named "anImage.gif".

Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜