title: How to repaint a JPanel after have drawn on it?
body: <p>I have a component that inherits from JPanel, I draw a grid on it. Now I have a JComboBox and I want the user to be able to choose the grid size here and then press a button to make the grid change (repaint the grid).</p>
  
  <p>The thing is that it paints the initial grid, but once the user choses a grid size from the JComboBox and clicks the button, nothing happens. I have to minimize the form and then restore it again to see the changes.</p>
  
  <p>Any Ideas? The Code is below.</p>
  
  <h2>The Component:</h2>
  
  <pre><code>public class Board extends JPanel {
      ...
  
      protected void paintComponent(Graphics og) {
          super.paintComponent(og);
          ...
          }
      }    
  }
  </code></pre>
  
  <h2>Main Class</h2>
  
  <pre><code>public class Main extends javax.swing.JFrame {
  ...
  
  public Main() {                                   //This works great.
      board = new Board( ... );
      somePanel.add(board, BorderLayout.CENTER);
  
  }
  
  public void someButtonActionPerformed(Event e) { //This is not working
  
      somePanel.remove(board);
      board = new Board( ... );
      somePanel.add(board);
      somePanel.invalidate()
      board.repaint();
  }
  </code></pre>