Problem copying WidgetCollection to GWT?

I have a rather strange problem

When copying one WidgetCollectionfrom one FlowPanelto another. Widgetsin WidgetCollectionmove instead of copying. Because of this pair of widgets remain in the previous panel.
Here is my code:

    final FlowPanel toDelete = getWidgetByID(from);
    final FlowPanel toPaste = getWidgetByID(to);
    final Iterator<Widget> iterator = toDelete.iterator();
    while (iterator.hasNext()) {
        toPaste.add(iterator.next());
    }

and the 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
    }

What is wrong here? Thanks in advance.

+3
source share
1 answer

When you add a widget to a new panel, it is automatically removed from the previous panel. There is no super-easy way around this. You need to create a new instance of each widget, and then add this copy.

, toDelete.getWidget(i) toDelete.getWidget(0). toDelete .

+1

All Articles