tags:

views:

126

answers:

2

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);
+4  A: 

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.

Robert Munteanu
+1  A: 

When you add a widget as a child to another widget, the containing class will first do a removeFromParent operation. So no you can not add a widget twice.

Why would you want to do that ? Maybe that is the right question to ask. If you don't want to update the status on multiple locations on the screen then maybe you need to apply an observer pattern to your data and update all the observers when the data changes.

David Nouls