title: How can I refresh a JScrollPane after choosing an element from a JComboBox?
body: <p>I have a JComboBox, and I want to load in a JScrollPane a different content everytime I choose a different element from the JComboBox. The content consists of a various number of JLabels and JTextFields.</p>
  
  <p>What I have done:</p>
  
  <pre><code>JScrollPane scrollPane;
  JComboBox combo;
  
  JPanel back = new JPanel(new BorderLayout());
  combo = new JComboBox({ "Bird", "Cat", "Dog", "Rabbit", "Pig" });
  combo.addActionListener(new AnimalLoader());
  scrollPane = showPanel((String) combo.getSelectedItem());
  
  back.add(combo, BorderLayout.NORTH);
  back.add(scrollPane, BorderLayout.SOUTH);
  
  back.setVisible(true);
  
  protected JScrollPane showPanel(String name)
  {
       JPanel contentPanel = new JPanel(new JLabel(name));
       scrollPane = new JScrollPane(contentPanel);
  
       return scrollPane;
  }
  
  private class AnimalLoader implements ActionListener
  {
       public void actionPerformed(ActionEvent e)
       {
              JComboBox cb = (JComboBox) e.getSource();
              String selected = (String) cb.getSelectedItem();
              scrollPane = showPanel(selected);              
       }
  }
  </code></pre>
  
  <p>I didn't manage to make this reload a different JScrollPane when I choose another item.
  Only the JScrollPane that belongs to the first item (the default one) of the JComboBox is loaded.</p>
  
  <p>Any ideas of what I've done wrong please?</p>