在 GWT 中复制 WidgetCollection 时出现问题?
我有一个很奇怪的问题,
将一个 WidgetCollection
从一个 FlowPanel
复制到另一个 FlowPanel
时。 WidgetCollection
中的 Widget
正在移动而不是复制。因为这对小部件保留在之前的面板中。
这是我的代码:
final FlowPanel toDelete = getWidgetByID(from);
final FlowPanel toPaste = getWidgetByID(to);
final Iterator<Widget> iterator = toDelete.iterator();
while (iterator.hasNext()) {
toPaste.add(iterator.next());
}
和下一个版本:
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
}
这里出了什么问题? 提前致谢!!!
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.
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 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's wrong here?
Thanks in advance!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您将小部件添加到新面板时,它会自动从之前的面板中删除。没有超级简单的方法可以解决这个问题。您需要为每个小部件创建一个新实例,然后添加该副本。
如果您的目标只是将小部件从一个面板移动到另一个面板,只需将
toDelete.getWidget(i)
更改为toDelete.getWidget(0)
即可。您还可以考虑仅移动toDelete
面板本身,而不是移动其所有小部件。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)
totoDelete.getWidget(0)
. You might also consider just moving thetoDelete
panel itself instead of moving all of its widgets.