GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.weightx = 100.0; constraints.weighty = 100.0;  Component[] items = getComponents(); for (int i = index; i < items.length; i++) { constraints.gridy = i; super.add(items[i], constraints, i); } this.setSize(this.getPreferredSize());
revalidate();
  public void remove(int index)  {    super.remove(index);    GridBagConstraints constraints = new GridBagConstraints();    constraints.fill = GridBagConstraints.BOTH;    constraints.weightx = 100.0;    constraints.weighty = 100.0;    Component[] items = getComponents();    for (int i = index; i < items.length; i++)      {	constraints.gridy = i;	super.add(items[i], constraints, i);      }    this.setSize(this.getPreferredSize());  }