简体   繁体   中英

How to change image in GWT

I've got some problems with class Image, from GWT.

I create Image, something like that:

Image img = new Image(path);

and then, I add to this variable click handler. And I want to change image after clicking on it. Now I'm doing it in this way, that I have second Image:

Image img2 = new Image(path2);

and after clicking first Image (img) I remove it from panel and I add second Image (img2).

Does GWT offer any function to change it in better way? I've got some other widgets in my panel so removing everything and then adding it with one diffrent element is very problematic for me.

Why don't you use the setUrl method of the GWT Image widget ?

See the javadoc .

Example: img.setUrl('my/new/image.png');

您可以将两个图像都添加到页面,通过调用img2.setVisible(false)将img2隐藏,然后在单击处理程序中将img隐藏并取消隐藏img2。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM