title: Swing JPanel won't repaint
body: <p>I have a simple object which extends <code>JPanel</code>, when the <code>update()</code> method is called on this object it it meant to add some labels to the panel and then repaint. However the labels do not show up after the update method is called, below is the code for update:</p>
  
  <pre><code>public void update(){
          GridBagConstraints constraints = new GridBagConstraints();
  
          if(cardsHidden){
              for(int i = 0; i &lt; 2; i++){
                  constraints.gridx = i;
                  constraints.gridy = 0;
                  JLabel card = new JLabel(PlayingCards.cardImages[PlayingCards.CARD_BACK_INDEX]);
                  add(card, constraints);
              }
          }
          else{
              Card[] holeCards = player.getHoleCards();
              for(int i = 0; i &lt; holeCards.length; i++){
                  constraints.gridx = i;
                  constraints.gridy = 0;
                  JLabel card = new JLabel(holeCards[i].getImageIcon());
                  add(card, constraints); 
              }
          }
  
          validate();
          repaint();
      }
  </code></pre>
  
  <p>any ideas? </p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>solved:</p>
  
  <p>It turns out that the <code>HoleCardsPanel</code> wasn't adding to its parent frame properly.  Once that was fixed the adding of new <code>JLabel</code>s works fine. I also:</p>
  
  <ul>
  <li>added the call to the <code>update()</code> method to the event dispatch thread using <code>SwingUtillities.invokeLater</code></li>
  <li>had to call <code>validate()</code> from the uppermost component (in this case the <code>JFrame</code>) as Devon_C_Miller <a href="https://stackoverflow.com/a/2157762/1048186">suggests in his answer</a>.</li>
  </ul>