title: JPanel disappearing when moved on specific Tile in GridBagLayout
body: <p>I have a <code>JLayeredPane</code> laid out with a <code>GridBagLayout</code> in which another <code>JPanel</code> is moving on user's key input. </p>
  
  <p>Everything works fine, the panel (called dot) moves fine, but on the last <code>Tile</code> of the <code>Grid</code> (meaning the bottom-right corner) it disappears. The program still runs afterward, I can move the dot Panel in and out of this Tile normally, but it just doesn't appear on the screen.</p>
  
  <p>So here is my code for the <code>GridPane</code> holding the <code>Tile</code>: </p>
  
  <pre><code>public class GridPane extends JLayeredPane {
      public int rows;
      public int columns;
  
      private List&lt;List&lt;Tile&gt;&gt; tileGrid;
      private GridBagConstraints gbc = new GridBagConstraints();
      private KeyListener kl = new KeyListener() {
  
          @Override
          public void keyTyped(KeyEvent e) {
  
          }
  
          @Override
          public void keyReleased(KeyEvent e) {
              // TODO Auto-generated method stub
  
          }
  
          @Override
          public void keyPressed(KeyEvent e) {
                  switch (e.getKeyCode()) {
                      case KeyEvent.VK_RIGHT:
                      if(dotTile.column &lt; columns-1)
                      dotTile = tileGrid.get(dotTile.row).get(dotTile.column+1);
                          break;
                  case KeyEvent.VK_LEFT:
                      if(dotTile.column != 0)
                      dotTile = tileGrid.get(dotTile.row).get(dotTile.column-1);
                          break;
                  case KeyEvent.VK_DOWN:
                      if(dotTile.row &lt; rows-1)
                      dotTile = tileGrid.get(dotTile.row+1).get(dotTile.column);
                          break;
                  case KeyEvent.VK_UP:
                      if(dotTile.row != 0)
                      dotTile = tileGrid.get(dotTile.row-1).get(dotTile.column);
                          break;
                  }
              //moving the dot
              remove(dot);
              gbc.fill = GridBagConstraints.NONE;
              gbc.anchor = GridBagConstraints.CENTER;
              gbc.gridx = dotTile.column;
              gbc.gridy = dotTile.row;
              add(dot, gbc, 1);
              revalidate();
              repaint();
          }
      };
  
      private JPanel dot = new JPanel();
      public Tile dotTile;
  
      public GridPane(int rows, int columns) {
  
          this.rows = rows;
          this.columns = columns;
  
          setLayout(new GridBagLayout());
          addKeyListener(kl);
          setFocusable(true);
  
          //fill array and JPanel with Tile
          tileGrid = new ArrayList&lt;List&lt;Tile&gt;&gt;(rows);
          for (int i = 0; i &lt; rows; i++) {
              List&lt;Tile&gt; rowList = new ArrayList&lt;Tile&gt;(columns);
              for(int j=0; j &lt; columns; j++) {
                  Tile t = new Tile(randomColor(), i, j);
                  rowList.add(t);
                  gbc.fill = GridBagConstraints.HORIZONTAL;
                  gbc.gridx = j;
                  gbc.gridy = i;
                  add(t, gbc, 0);
              }
              tileGrid.add(rowList);
          }
  
          dot.setPreferredSize(new Dimension(20, 20));
          dot.setBackground(Color.BLACK);
  
          //set initial position of dot
          dotTile = tileGrid.get(rows/2+1/2).get(columns/2+1/2);
          gbc.fill = GridBagConstraints.NONE;
          gbc.anchor = GridBagConstraints.CENTER;
          gbc.gridx = dotTile.column;
          gbc.gridy = dotTile.row;
  
          add(dot, gbc, 1);
          repaint();
      }
  
      private Random r = new Random();
      public Color randomColor() {
          return new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255));
  
      }
  
      Color c = new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255));
      private Color gradientColor() {
          c = c.darker();
          return c;
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/6Fju2.png" alt="The black square is the dot panel moving around the grid. It disappears only when it is in the bottom-right Tile"></p>