duplicate component

Hi:

I have a component (i.e. a table) that is added to a layout (layout A)…now, when I push a button, I want to add the same component to a second layout (layout B ) but not remove it from the first component…This partially works (using addComponent in both layouts) because when I add it to layout B, it is removed from layout A…how can I duplicate the component with all of its characteristics to add it to the second layout??

regards, and thank you very much…

It is not possible, component needs to be unique.
You will have to make a new one and copy the state of the first one to the new.

A component cannot be located in two layout at the same time.

In your case, I think you have no choice to create a new Table.

Regards.

Thank you very much for your answers…but, what would be the best way to copy all the attributes from one component to another? If it is a simple component like a Label is not difficult, but with a more complex component like a table with data, listeners, etc it can be somehow tedious…

You can do table2.setComponentDataSource(table1.getComponentDataSource()) to share the same data.
And iterate over the listeners of table1 and add them to table2.

That should already take care of most of it.

Thank you very much Mathias…

There should be something like getComponentAttributes() to make two or more components exactly eaqual though…but anyway…thank you very much for your answer…