View Full Version : ContentPanel removing and adding items

13 Oct 2009, 3:09 AM
I'm a little confused about this one and am not able to find a solution.

I've got a ContentPanel (parent) that contains another ContentPanel (idlePanel). When an event occurs triggered by and drag and drop I remove idlePanel from parent and add activePanel. Something like this:

DropTarget target = new DropTarget(xxx) {
protected void onDragDrop(DNDEvent event) {
Info.display("MessageBox", "Event occured");
parent.remove(idlePanel) ;
parent.add(activePanel) ;
render(parent.getElement()) ;

The problem I'm getting is that the first time the event occurs the activePanel doesn't display. It displays the header of activePanel but not it's contents.
This parent panel sits in a TabPanel. If you get to this state where activePanel's content is not displayed and then change to another tab and back again then activePanel's content is now displayed correctly.

I'm guessing this is because I need to prerender activePanel?

If the event happens a second time it displays activePanel correctly however none of the buttons in that panel work. Again by changing to another tab and back again these buttons start working again.

I'm guessing that after removing idlePanel from parent and adding activePanel I need to wake it up in some way and get it to render and function properly but I'm not sure how to do this.

Anyone got any tips on the correct way to do this?


13 Oct 2009, 3:48 AM
Posted to soon. Managed to find the method I needed by trial and error.

adding activePanel.layout() after switching the panels seems to be working for me.

22 Oct 2009, 4:16 AM
Can someone confirm the best way to remove and add something to a ContentPanel and get the result to display properly. The solution I have above doesn't seem to always work.

I currently have a Viewport that contains a ContentPanel with a login form. On submit I want to remove the loginContactPanel from the Viewport and add activeContentPanel. When I do:

view.removeAll() ;
view.add( mainPanel ) ;

I just end up with a blank screen. The new ContentPanel is displayed properly if you resize the window.

22 Oct 2009, 4:18 AM
You need to call layout after the modifications:

view.removeAll() ;
view.add( mainPanel ) ;

22 Oct 2009, 4:24 AM
Thanks that did work.

I was calling layout on the activeContentPanel rather than the Viewport.