GWT动态更改图像 [英] GWT Dynamically Changing an Image

查看:128
本文介绍了GWT动态更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 元素changedImage;元素changedImage;元素changedImage; 
/ * imageID是前一张图片的ID * /
changedImage = Document.get()。getElementById(imageId);
/ * myImageBundle是资源Bundle并且图标是新图像* /
changedImage.setInnerHTML(myImageBundle.icon()。getHTML());

但没有任何反应,它是相同的图像。我错过了什么?



非常感谢您的回答或建议。

- -------解决方案---------------



我找到了一个解决方案,它工作正常,但不知何故,我认为这不是最好的。一切都在下一个函数中:

pre $ private $ switchImage(AbstractImagePrototype imageBundled){

String newStyleFromImageBundle,值;
value =style =;

newStyleFromImageBundle = extractStyle(value,imageBundled.getHTML());

Element e = Document.get()。getElementById(imageHeaderLogo);
//移除当前样式
e.removeAttribute(style);
//设置新样式与前一个从图像捆绑的html
中检索e.setAttribute(style,newStyleFromImageBundle);


}

希望它有帮助,随时可以告诉如果有更好的方法来做到这一点,或者这是你见过的最糟糕的...... :-)。

解决方案

我认为这特别是 applyTo 是for。为什么你不这样做:

  / *假设id为imageId的元素是真实图像
元素并且未定义:* /
myImageBundle.icon()。applyTo(Image.wrap(Document.get()。getElementById(imageId)));

//编辑后使用Image.wrap

以上应用您在图标()中定义的图像为ID为imageId的图像


I want to change dynamically an image by using the ID and a Ressource Bundle.

Element changedImage;
 /* imageID is the Id for the previous image */
 changedImage = Document.get().getElementById("imageId");
 /* And myImageBundle is the resource Bundle and icon the new image*/
 changedImage.setInnerHTML(myImageBundle.icon().getHTML());

But nothing happens , it's the same image . Did i miss something ?

Thanks a lot for answer(s) or suggestions(s).

-------- Solution ---------------

I've found a solution , it works properly, but somehow i think it's not the best one . Everything is on the next function :

    private void switchImage(  AbstractImagePrototype imageBundled) {

    String newStyleFromImageBundle, value;
    value = "style=";

    newStyleFromImageBundle = extractStyle(value ,imageBundled.getHTML());

    Element e = Document.get().getElementById("imageHeaderLogo");       
    // removing the current style
    e.removeAttribute("style");     
    // setting the new style with the  previous one retrieved from the image bundled's html
    e.setAttribute("style",newStyleFromImageBundle );


}

Hope it helps, feel free to tell if there's a better way to do it or this the worst you 've ever seen .. :-) .

解决方案

I think this is specifically what applyTo is for. Why don't you just do the following:

/*assuming that the element with id "imageId" is a real image 
element and is not undefined:*/
myImageBundle.icon().applyTo(Image.wrap(Document.get().getElementById("imageId")));

//editted to use Image.wrap

The above should apply the image you have defined in icon() to the image with id "imageId"

这篇关于GWT动态更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆