GWT动态更改图像
我想使用ID和Ressource包动态更改图像GWT动态更改图像,gwt,bundle,Gwt,Bundle,我想使用ID和Ressource包动态更改图像 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(m
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());
但什么也没发生,这是同一个画面。我错过什么了吗
非常感谢您的回答或建议
--------解决方案---------------
我已经找到了一个解决方案,它工作正常,但不知何故我认为它不是最好的。一切都在下一个功能中:
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 );
}
希望能有所帮助,请随时告诉我是否有更好的方法来做这件事,或者这是你见过的最糟糕的事情 我想这就是我们的目的。你为什么不做以下几件事:
/*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
以上内容应将您在icon()中定义的图像应用于id为“imageId”的图像。我已经尝试了您编写的内容,但我收到了下一条错误消息:“无法从元素到图像进行转换”我认为这与您所说的“asuming that…”有关。id的原始来源是:AbstractImagePrototype img;imgBundled=getMyImageBundle().icon();Image Image=imgBundled.createImage();image2.setStyleName(“imageCenterPanel”);image2.getElement().setId(“imageId”);是的,很抱歉,您不能将元素强制转换为小部件。如果您有对通过createImage创建的图像的引用(我认为这是image2的意思),则将其传递给applyTo,而不是Document.get().getElementById(“imageId”)。如果没有引用,则尝试将元素强制转换为AbstractImagePrototype.ImagePrototypeElement:myImageBundle.icon().applyTo((AbstractImagePrototype.ImagePrototypeElement)Document.get().getElementById(“imageId”);您当然也可以将元素包装成一个图像:…icon().applyTo(Image.wrap(Document.get().getElementById(“imageId”))很抱歉,我花了很长时间回答你的回答。我会尽快或稍后尝试你的建议。我在我的项目中少了一点。我会回到项目的这一部分,尝试你的回答。谢谢你的回答。