0

I want to remove all elements from a ContentPanel on a mouse click event and add new ones. It is working fine with removeAll() method, this removes all existing components. But when I want to add a new Component it is not added.

Ali Asad Sahu
  • 57
  • 1
  • 3
  • 9
  • 1
    Can you post your code please? You probaly don't use the reference correctly... – Sam May 08 '12 at 20:34

1 Answers1

2

Maybe something like this i omitted the click handler but you should get the idea from this.

private ContentPanel contentPanel;

public SwapScreen() {
 contentPanel = new ContentPanel();
 add(contentPanel);
}

public void swap1() {

   /*This should be split into a separate
    method and called only once to avoid recreating them.*/
   field1 = new TextField<String>();
   contentPanel.add(field1);

   field2 = new TextField<String>();
   contentPanel.add(field2);

  this.layout(true);
}

public void swap2() {

   /*This should be split into a separate
    method and called only once to avoid recreating them.*/
   anotherField1 = new TextField<String>();
   contentPanel.add(anotherField1);

   anotherField2 = new TextField<String>();
   contentPanel.add(anotherField2);

   this.layout(true);
}

Most important part is this.layout(true) to force it to refresh your layout,

AbstractChaos
  • 4,211
  • 1
  • 19
  • 28