Using a button to refresh a panel in GWT

I have a small web application project using GWT, where a button handles an event: populating a panel with widgets. Currently, clicking the button a second time will duplicate the panel, i want it so it clears the panel, and re adds the widgets.

So far I have:

final Button b = new Button("get schools near me");
    final HorizontalPanel panel = new HorizontalPanel();
    panel.getElement().setId("distanceTable");
    RootPanel.get("core").add(b);
    RootPanel.get("core").add(panel);
    b.addClickHandler(new ClickHandler(){
        @Override
        public void onClick(ClickEvent event) {
            Timer t = new Timer(){
                @Override
                public void run() {
                    //how do you clear the panel here first? before you
                    // do a bunch of things along the lines of:
                    panel.add(widget);
                    panel.add(widget2);
                }
            };
            t.schedule(1400); // wait 1.4 seconds for callback
        }
    });

I get that anything you pass to the run function has to be as a final declaration, so how do I get around this?

Answer

You can use the clear method:

panel.clear();

Leave a Reply

Your email address will not be published. Required fields are marked *