jrola
jrola

Reputation: 416

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.

Upvotes: 0

Views: 2233

Answers (2)

Zzzzz
Zzzzz

Reputation: 136

You can add both images to the page, make img2 hidden by calling img2.setVisible(false) and then in the click handler, make img hidden and unhide img2.

Upvotes: 0

Sandro Munda
Sandro Munda

Reputation: 41078

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

See the javadoc.

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

Upvotes: 4

Related Questions