title: JPanel don't repaint after setLocation
body: <p>I want to make a Ludo/Parcheesi game, so I use <code>GridLayout</code> (11x11) to add pieces on board.</p>
  
  <p><a href="https://i.stack.imgur.com/xdkXG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xdkXG.png" alt="enter image description here"></a></p>
  
  <p>I have a problem with green, blue and yellow pawns (only red pawns are paint correct 
   and appear at new <code>setLocation</code>). After I roll the dice and <code>setLocation</code> of pawn to start cell, pawn disappear(I don't know why doesn't repaint at new location). I test the <code>mouseClicked</code> event to <code>getLocation</code> of pawns and the new location it's correct but pawns don't appear anymore.</p>
  
  <p>This is Pawn class:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class Pawn extends JPanel {
      private int id;
      private Color color;
      private String sColor;
      private int position;
      private boolean isActive;
      private Point homeCoords;
      private Point currentCoords;
  
      //isActive = FALSE means pawn in HOME
  
      public Pawn(int id, String color, Point currentCoords) {
          this.currentCoords =
  
   new Point(currentCoords);
          this.id = id;
          position = -1;
          isActive = false;
          sColor = color;
  
      switch (color) {
          case "RED": {
              this.color = Color.red;
              break;
          }
          case "GREEN": {
              this.color = Color.green;
              break;
          }
          case "BLUE": {
              this.color = Color.blue;
              break;
          }
          case "YELLOW": {
              this.color = Color.yellow;
              break;
          }
      }
  }
  
  public void setInitialPosition() {
      Point p = getLocation();
      homeCoords = p;
  //        System.out.println("[" + sColor + " " + id + "] = Location: " + homeCoords);
      currentCoords = new Point(homeCoords.x, homeCoords.y);
  }
  
  public void start() {
      position = 0;
      isActive = true;
      setPosition();
  }
  
  public void increasePosition(int moves) {
      position += moves;
      setPosition();
  }
  
  public boolean isActive() {
      return isActive;
  }
  
  public int getPosition() {
      return position;
  }
  
  public int getId() {
      return id;
  }
  
  public boolean getOut(Pawn pawn) {
      return ((currentCoords.getX() == pawn.currentCoords.getX()) &amp;&amp; (currentCoords.getY() == pawn.currentCoords.getY()));
  }
  
  public void goHome() {
      position = -1;
      isActive = false;
      setPosition();
  }
  
  @Override
  protected void paintComponent(Graphics g) {
      super.paintComponent(g);
  
      g.setColor(color);
      g.fillOval(0, 0, getWidth(), getHeight());
      setLocation((int) currentCoords.getX(), (int) currentCoords.getY());
  //        System.out.println("[" + sColor + " " + id + "] = Location: " + currentCoords);
  }
  
  public void setPosition() {
      switch (sColor) {
          case "RED": {
              switch (position) {
                  case -1: {
                      currentCoords = new Point((int) homeCoords.getX(), (int) homeCoords.getY());
                      setLocation((int) homeCoords.getX(), (int) homeCoords.getY());
                      break;
                  }
                  case 0: {
                      currentCoords = new Point(0, 274);
                      setLocation(0, 274);
                      break;
                  }
                  case 1: {
                      currentCoords = new Point(81, 274);
                      setLocation(81, 274);
                      break;
                  }
                 //and so on...
              }
  
  
      System.out.println("RED NEW POSITION: " + currentCoords);
                  break;
              }
              case "GREEN": {
                  switch (position) {
                      case -1: {
                          currentCoords = new Point((int) homeCoords.getX(), (int) homeCoords.getY());
                          setLocation((int) homeCoords.getX(), (int) homeCoords.getY());
                          break;
                      }
                      case 0: {
                          currentCoords = new Point(486, 2);
                          setLocation(486, 2);
                          break;
                      }
                      case 1: {
                          currentCoords = new Point(486, 70);
                          setLocation(486, 70);
                          break;
                      }
  `//and so on..`.
                  }
                  System.out.println("GREEN NEW POSITION: " + currentCoords);
                  break;
              }
              case "BLUE": {
                  switch (position) {
                      case -1: {
                          currentCoords = new Point((int) homeCoords.getX(), (int) homeCoords.getY());
                          setLocation((int) homeCoords.getX(), (int) homeCoords.getY());
                          break;
                      }
                      case 0: {
                          currentCoords = new Point(324, 682);
                          setLocation(324, 682);
                          break;
                      }
      // and so on...
  
                  System.out.println("YELLOW NEW POSITION: " + currentCoords);
                  break;
              }
          }
      }
  }
  </code></pre>
  
  <p>So, I have a <code>JPanel</code> for player's pawns with <code>MouseAdapter</code> for <code>mouseClicked</code> to move the pawn X positions after player roll the dice:</p>
  
  <pre><code>    public Playground(int noPlayers) {
  
      //some JButtons and variable ...
  
          JPanel board = new JPanel(new GridLayout(11, 11));
          int redPawnCount = 0, greenPawnCount = 0, bluePawnCount = 0, yellowPawnCount = 0;
  
             //generate the board with pawns and cells
  
                  Pawn temp = players.get(0).getPawn(redPawnCount++);
                  pawns.add(temp);
                  temp.addMouseListener(new MouseAdapter() {
                      @Override
                      public void mouseClicked(MouseEvent e) {
                          super.mouseClicked(e);
                          System.out.println("RED PAWN");
  
                          for (int i = 0; i &lt; 4; i++)
                              System.out.println(players.get(0).getPawn(i).getLocation());
  
                          if (!hasMoved &amp;&amp; playerTurn == 0) {
                              if (temp.isActive()) {
                                  if ((temp.getPosition() + diceResult &lt;= 43) &amp;&amp; !checkFriendlyPawnsSamePosition(0, temp, temp.getPosition() + diceResult)) {
                                      temp.increasePosition(diceResult);
                                      checkForEnemy(0, temp);
                                      hasMoved = true;
                                  } else {
                                      System.out.println("[INFO] Cannot move there.");
                                      return;
                                  }
                              } else if (!temp.isActive() &amp;&amp; diceResult == 6 &amp;&amp; !checkFriendlyPawnsSamePosition(0, temp, temp.getPosition() + diceResult)) {
                                  temp.start();
                                  checkForEnemy(0, temp);
                                  hasMoved = true;
                              } else {
                                  if (diceResult == 6) {
                                      System.out.println("[INFO] The START cell is occupied.");
                                  } else {
                                      System.out.println("[INFO] Roll 6 to START.");
                                  }
                                  return;
                              }
                          } else {
                              if (playerTurn != 0) {
                                  System.out.println("[INFO] Not your turn.");
                              } else {
                                  System.out.println("[INFO] You already moved.");
                              }
                          }
                      }
                  });
                  board.add(temp);
  </code></pre>