Lunaetic
Lunaetic

Reputation: 229

GWT: Is adding the same Image twice not possible?

What I want to do is add units to a scale. One unit is an Image. So I decided to assign the URL to a global variable like this:

Image scaleUnit = new Image("example/url.xy");

And then I tried to add exactly this Object to the same FlowPanel twice like this:

examplepanel.add(scaleUnit);
examplepanel.add(scaleUnit);

This doesn't work as the result I get is only one Image inside of the FlowPanel. Why does this happen? Is it not possible to add the same Image twice or am I missing something?

Upvotes: 0

Views: 111

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64551

An Image is a Widget; it is ultimately a wrapper around a DOM element. You cannot add such an element twice in the DOM tree and expect it to display twice: the second insertion will first remove it from where it currently is. DOM elements can be cloned, but not widgets. In brief: no you can't, you have to create 2 Image widgets.

Upvotes: 2

Related Questions