title: Java GUI - remove all components and redraw
body: <p>I have a grid layout JPanel, with many icons drawn on it. I need the icons to change after the player moves because the map changes. Here's the method I came up with:</p>
  
  <pre><code>public void initGridIcons(JPanel pnl, String map) {
      pnl.removeAll();
      char[] tiles = map.toCharArray();
      for (char ch : tiles) {
          JLabel label = new JLabel("");
          String icon = "";
          switch (ch) { // lots of cases irrelevant to problem
          }
          label.setIcon(new ImageIcon(ClientGUI.class
                  .getResource("/resources/" + icon)));
          pnl.add(label);
      }
  }
  </code></pre>
  
  <p>This works initially, in that it does draw the player and the map correctly. However it doesn't change after each turn.</p>
  
  <p>I've tried using this method just with an iterator counter (change on even numbers) to make sure it wasn't any other code, and it doesn't work, so I'm sure it's this.</p>