How do you clear RootLayoutPanel in GWT?
- by kerrr
I have Buttons attached to elements on the modules entrypoint html page using RootPanel.get("foo").add(button). If I subsequently create a LayoutPanel and attach it using RootLayoutPanel.get.add(layoutpanal) then the buttons cannot be clicked. This is all fine. If I then try and remove the layoutpanel or clear the RootLayoutPanel the buttons still cannot be clicked.
Any ideas how to clear this? Have I missed a step or should you simply never try and get back to using a page's RootPanel if you have used a RootLayoutPanel?
Sample code:
public void onModuleLoad(){
final LayoutPanel lp1=new LayoutPanel();
ClickPanel ping=new ClickPanel("Ping");
ping.getElement().getStyle().setBackgroundColor( "#fdd" );
ping.addClickHandler( new ClickHandler(){
@Override
public void onClick( ClickEvent event ){
Window.alert( "Ping!!!" );
//lp1.removeFromParent();
//RootLayoutPanel.get().remove(lp1);
//RootLayoutPanel.get().removeFromParent();
RootLayoutPanel.get().clear();
}
} );
ClickPanel bong=new ClickPanel("Bong");
bong.getElement().getStyle().setBackgroundColor( "#ddf" );
bong.addClickHandler( new ClickHandler(){
@Override
public void onClick( ClickEvent event ){
Window.alert( "Bong!!!" );
}
} );
lp1.add( ping );
lp1.setWidgetLeftWidth( ping, 100, Style.Unit.PX, 500, Style.Unit.PX );
lp1.setWidgetTopHeight( ping, 100, Style.Unit.PX, 500, Style.Unit.PX );
lp1.add( bong );
lp1.setWidgetLeftWidth( bong, 50, Style.Unit.PCT, 600, Style.Unit.PX );
lp1.setWidgetTopHeight( bong, 50, Style.Unit.PCT, 200, Style.Unit.PX );
Button b=new Button("Click Me");
b.addClickHandler( new ClickHandler(){
@Override
public void onClick( ClickEvent event ){
RootLayoutPanel.get().add( lp1 );
}
} );
RootPanel.get("button1").add( b );
}
ClickPanel is simply overrides HTMLPanel implementing HasClickHandelers. Clicking "Click Me" opens the layout panel. Clicking the panel ping gets rid of the layout panel, but the button "Click Me" cannot be clicked. I've tried various options.