Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin - Remove Component from its parent

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.

like image 769
Sean Connolly Avatar asked Jan 15 '14 20:01

Sean Connolly


2 Answers

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

like image 181
Mubasher Avatar answered Sep 19 '22 00:09

Mubasher


Or like this if child was added to layout.

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

I think this is better than Mubasher solution because it's implementation independent, I mean you don't have to know the Parent layout and if it changes the code still works.

like image 35
siulkilulki Avatar answered Sep 19 '22 00:09

siulkilulki