Vaadin - Remove Component from its parent

Sean Connolly picture Sean Connolly · Jan 15, 2014 · Viewed 8.2k times · Source

In the Vaadin framework (v7.1.9), how do we remove a Component from it's parent?

I'm only aware of the removeComponent function, but that requires me to get a handle on the parent (ugly):

ComponentContainer parent = (ComponentContainer) child.getParent();
parent.removeComponent(child);

I tried to just detach the child but that removed it from the 'application' without removing the Component from the UI.

Answer

Mubasher picture Mubasher · Jan 16, 2014

if Child is added to Any Layout you should cast it to that layout e.g if child ws added to AbsoluteLayout then

AbsoluteLayout parent = (AbsoluteLayout ) child.getParent();
parent.removeComponent(child);

Try this one