TabSheet - Component cannot be added inside it's own content

Using Vaadin 7.4.2.
Have TabSheet with 4 tabs (positiions set manualy) and trying to replace content of a tab upon it’s selection.
Listener is added using addSelectedTabChangeListener method and it gets invoked.
In the event handler I have:

TabSheet tabSheet = evnet.getTabSheet();
int selectedTabPosition = tabSheet.getTabPosition(
                tabSheet.getTab(
                        tabSheet.getSelectedTab()
                        )
      );
        if (1 == selectedTabPosition) {
            tabSheet.replaceComponent( tabSheet.getSelectedTab(), getAnotherTabComponent() );
        }

Line 8 is throwing
java.lang.IllegalArgumentException: Component cannot be added inside it’s own content
Any ideas?

Hello Marko,

This kind of error you get when you try to add a component in to itself. As you have not shared your complete code just have a look at type the component getAnotherTabComponent() is returning, once you identify it would solve the problem.

Cheers,
Krishna.

Thank you Krishna,
u are right, I had an error elsewhere in the code, was setting compoinsition root badly.

Cheers,
Marko