title: actionPerformed acts on all custom JPanels at once
body: <p>I'm creating a GUI to show output from a database.</p>
  
  <p>Currently I'm adding <code>CoursePanel extends JPanel</code> to a <code>JScrollPane</code>, to emulate rows in a list. I can't use <code>JList</code> with <code>ListCellRenderer</code> as I need each row to have functionality beyond a simple click.</p>
  
  <p>Each <code>CoursePanel</code> has a <code>JButton</code> on it. When clicked, the button adds a new row to the <code>CoursePanel</code> and displays some extra information.</p>
  
  <p>However, when I bind an <code>ActionListener</code> to the button to increase the number of rows in the GridLayout, it adds a row to every instance of <code>CoursePanel</code>. However, only the current <code>CoursePanel</code> extra row is set visible. Can anyone offer advice on what is going wrong?</p>
  
  <pre><code>public class CoursePanel extends JPanel{
      public CoursePanel(){
  
          this.setLayout(new GridLayout(1, 1);
  
          JPanel infoPanel = new JPanel();
  
          JPanel extraPanel = new JPanel();
          extraPanel.add(new JLabel("test"));
          extraPanel.setVisible(false);
  
          JButton revealBtn = new JButton("Reveal");
  
          revealBtn.addActionListener(e -&gt; {
  
              //this line happens for every CoursePanel in the scroll pane
              //meaning every row suddenly doubles in width
              ((GridLayout)this.getLayout()).setRows(2);
  
  
              //this only happens for the instance of CoursePanel who's button is clicked!
              //i.e. the JLabel with "test" only appears in the row who's button is clicked
              this.add(extraPanel);
              extraPanel.setVisible(true);
          });
  
          infoPanel.add(revealBtn);                     
  
          this.add(infoPanel);
      }
  }
  
  //where the scroll panel is built
  JPanel contentPanel = new JPanel();
  JScrollPane scrollPane = new JScrollPane();
  scrollPane.setViewportView(contentPanel);
  
  for(rows in database){
      //...some code to add new rows to the scrollpane...
  
      contentPanel.add(new CoursePanel(row));    
  
  }
  </code></pre>
  
  <p>Before clicking:</p>
  
  <p><a href="https://i.stack.imgur.com/is57g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/is57g.png" alt="Before clicking anything"></a></p>
  
  <p>After clicking Bobby's button, note the gaps the same size as the 'test' row under every row:</p>
  
  <p><a href="https://i.stack.imgur.com/E74Lf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E74Lf.png" alt="After clicking Bobby&#39;s button"></a></p>