title: JPanel not updating when using invalidate, validate and repaint
body: <p>I have a problem that one of my <code>JPanels</code> doesn't update itself according to the window when its supposed too. I shall try and briefly explain whats happening. A list of characters is fed into an <code>arraylist</code> (named lookReply) from another class (this works as I've tested this) it then uses <code>2 iterations</code> to assign each one to a coordinate in a square table made from <code>JLabels</code>. These <code>JLabels</code> are in the lookReplyGUIPanel <code>JPanel</code>. After a button is pressed new characters get loaded into the <code>arraylist</code> and it repeats itself. However the window does not show this update. I know they are getting fed into the <code>JLabels</code> through some tests but its just the updating of the window doesn't seem to be working. I am using <code>invalidate, validate and repaint</code> but it still doesn't work. Please see my code below for the parts needed.</p>
  
  <p>The first method called - deals with the arraylist then calls the other method.</p>
  
  <pre><code>private void look()
  {
      //clear arrayList then add new lookReply to it
      lookReply.clear();
      while (HumanUser.lookReply==null)
      {
      }
      for(int n = 0; n&lt;HumanUser.lookReply.length(); n++)
      {
          lookReply.add(HumanUser.lookReply.charAt(n));                   
      }
      lookReply();
  //UP TO HERE WORKS FINE
  
      screen.invalidate();
      screen.validate();
      screen.repaint();
  }
  </code></pre>
  
  <p>The method which deals with the <code>JPanel</code> in question.</p>
  
  <pre><code>/**
   * Made up of several smaller JPanels each relate to 1 map position from the lookReply command.
   */
  private JPanel lookReply()
  {
      JPanel lookReplyGUIPanel = new JPanel(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
      Border blackline = BorderFactory.createLineBorder(Color.black);
  
  
      //Create a square table dependent on the radius of view.
      //Then fill each cell with the block retrieved from the lookReply arrayList.
      for(int y = lookReplyY; y&gt;0; y--)
      {
          for(int x = lookReplyX; x&gt;0; x--)
          {wall...
              //Then assign it to a variable which is used in the JLabel.
              String item = null;
              if (lookReply.size()!=0)
              {
                  item = lookReply.get(x*y-1) + "";
              }
              //ADD TO CHECK WHAT EACH ITEM IS AND USE THE RELEVENT PICTURE
              JLabel lookx = new JLabel(item);
              int width = (2*screenHeight/(5*lookReplyX)-10);
              lookx.setPreferredSize(new Dimension(width, width));
              lookx.setBorder(blackline);
              c.gridx = x;
              c.gridy = y;
              lookReplyGUIPanel.add(lookx, c);
          }
      }
      return lookReplyGUIPanel;
  }
  </code></pre>
  
  <p>Some more details of the overview of everything if this helps. The first method called adds all the <code>JPanels</code> to the <code>JFrame</code> in the correct position using <code>gridBagConstraints</code>. The <code>JFrame</code> is created outside a method so all other methods can see it. All help much appreciated and happy to provide more details if needed! thanks</p>
  
  <p>Here is a simple compilable piece of code which demonstrates the same problem. Ignoring the fact the window has to be resized - every button click on <code>button</code> increments m by 1 and should update to display the <code>lookReply</code> method of a 5X5 table of m. However it does not.</p>
  
  <pre><code>import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  public class temp
  {
  JFrame screen = new JFrame("temp");
  int m = 1;
  
  
  public static void main(String[] args)
  {
      temp g = new temp();
      g.create();
  }
  
  private void create()
  {       
      screen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      screen.setLayout(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
  
      c.gridy = 0;
      screen.add(lookReply(), c);
  
  
      c.gridy = 1;
      screen.add(button(), c);
  
      screen.setVisible(true);
  }
  
  private JPanel lookReply()
  {
      JPanel lookReplyGUIPanel = new JPanel(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
  
      for(int y = 5; y&gt;0; y--)
      {
          for(int x = 5; x&gt;0; x--)
          {
              JLabel lookx = new JLabel((m + ""));
              c.gridx = x;
              c.gridy = y;
              lookReplyGUIPanel.add(lookx, c);
          }
      }
  
      screen.invalidate();
      screen.validate();
      screen.repaint();
      return lookReplyGUIPanel;
  }
  
  private JPanel button()
  {
      JPanel button = new JPanel(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
  
      JButton b = new JButton("button");
      b.setBorder(null);
      c.gridx = 2;
      c.gridy = 2;
      button.add(b, c);
      b.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              m++;
              lookReply();                
          }
      });
  
      return button;
  }
  </code></pre>
  
  <p>}</p>