PDA

View Full Version : Dynamic remove of a component in a ContentPanel



Kirua007
31 May 2010, 5:46 AM
Hi,

I would like to knwo how can I remove a component from a panel:

I try this :


ContentPanel cp = (ContentPanel) this.getWidget();
cp.removeAll();
cp.layout();

But component in the screen still be visible ....

With an dynamic add there is no problem , no problem with a dynamic sizing of the panel too

Thank you for your answer

sven
31 May 2010, 5:48 AM
You want to remove the ContentPanel or all children ofthis ContentPanel? With your code you remove all children of that contentpanel.

Kirua007
31 May 2010, 5:50 AM
All children of the panel in order to have a "blank" panel ...

sven
31 May 2010, 5:52 AM
Than that code is correct. If it is not working, please post a fully working testcase that implements EntryPOnit

Kirua007
31 May 2010, 8:40 AM
I found the origin of the problem

My panel doesn't contain classic component but my own component which extend composite (of GWT librairie)
My component :

public class ComplexField extends Composite {

ElementType myElement;
int size;
String label;
HorizontalPanel horizontalPanel;

public ComplexField(ElementType element,int size,String htmlLabel)
{
this.myElement=element;
this.size=size;
this.label = htmlLabel;
horizontalPanel = new HorizontalPanel();
horizontalPanel.setSpacing(10);

}

public ElementType getMyElement() {
return myElement;
}

public void removeAll()
{
HorizontalPanel horizontalPanel = (HorizontalPanel)this.getWidget();
horizontalPanel.removeAll();
horizontalPanel.layout();
}
}

With my own component, the removeAll of the panel doesn't work. Component stay on the screen
So I add the removeAll function on my component and I call it before calling removeAll of the Panel


ContentPanel panel = (ContentPanel)this;
for(int i=0;i<panel.getItemCount();i++)
{
ComplexField cf = (ComplexField)panel.getWidget(i);
cf.removeAll();
}

panel.removeAll();
panel.layout();


Like this, it's works but I am not sure of the solution ...

Is It normal ?

Thank you