Problem while copying WidgetCollection in GWT?
I have quite a strange problem ,
While copying one WidgetCollection
from one FlowPanel
into another one. Widgets
in WidgetCollection
are moving instead of copying.Because of this couple of widgets remain in previous Panel.
final FlowPanel toDelete = getWidgetByID(from);
final FlowPanel toPaste = getWidgetByID(to);
final Iterator<Widget> iterator = toDelete.iterator();
while (iterator.hasNext()) {
toPaste.add(iterator.next());
}
and next version:
final FlowPanel toDelete = getWidgetByID(from);
final FlowPanel toPaste = getWidgetByID(to);
final int count = toDelete.getWidgetCount();
for (int i = 0; i < count; i++) {
toPaste.add(toDelete.getWidget(i));// here, i'm getting IndexOutOfTheBounds exception
}
Wh开发者_如何学JAVAat's wrong here? Thanks in advance!!!
When you add a widget to a new panel, it is automatically removed from its previous panel. There's no super-easy way to get around this. You need to make a new instance of each widget and then add that copy.
If it's just your goal to move widgets from one panel to another, just change toDelete.getWidget(i)
to toDelete.getWidget(0)
. You might also consider just moving the toDelete
panel itself instead of moving all of its widgets.
精彩评论