两次添加相同的对象 [英] adding the same object twice

查看:117
本文介绍了两次添加相同的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签和两个面板.我想将标签添加到每个面板中,但是在渲染后仅显示一个标签.我可以创建第二个标签,但我认为,必须两次可以添加相同的标签.这是我的代码:

i have an label and two panels. i want to add the label into each panel, but after rendering is shown only one label. i can create second label, but i think, it must be possible to add the same label twice. Here my code:

// Create labels
Label sectorLabel = new Label("Bereich");

// Create panels/rows
HorizontalPanel row1 = new HorizontalPanel();
HorizontalPanel row2 = new HorizontalPanel();

// Add content to row1
row1.add(sectorLabel);

// Add content to row2      
row2.add(sectorLabel);

推荐答案

您不能将相同的窗口小部件添加到两个面板中,一个窗口小部件只能具有一个父级.

You can't add the same widget to two panels, a widget can have only one parent.

解决方案是简单地创建具有相同内容的第二个标签.

The solution is simply to create a second label with the same contents.

这篇关于两次添加相同的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆