title: checking a jPanelSquare for items
body: <p>Quick question. I have a jPanelSquareGrid with labels in some squares (image labels, representing chess pieces)</p>
  
  <p>now when I drag and drop a piece to a certain square, I want to check if there isn't already a chesspiece in it.</p>
  
  <p>Does anyone have any idea how I can check a jPanelSquareGrid for existing items inside a square?</p>
  
  <p>Thanks in advance!</p>
  
  <p>here are my mouse events</p>
  
  <pre><code>   public void mousePressed(MouseEvent e)
  {
      chessPiece = null;
      Component c =  chessBoard.findComponentAt(e.getX(), e.getY());
  
      if (c instanceof JPanel) return;
  
      Point parentLocation = c.getParent().getLocation();
      xAdjustment = parentLocation.x - e.getX();
      yAdjustment = parentLocation.y - e.getY();
      chessPiece = (JLabel)c;
      chessPiece.setLocation(e.getX() + xAdjustment, e.getY() + yAdjustment);
  
      layeredPane.add(chessPiece, JLayeredPane.DRAG_LAYER);
      layeredPane.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
  }
  
  /*
  **  Move the chess piece around
  */
  public void mouseDragged(MouseEvent me)
  {
      if (chessPiece == null) return;
  
      //  The drag location should be within the bounds of the chess board
  
      int x = me.getX() + xAdjustment;
      int xMax = layeredPane.getWidth() - chessPiece.getWidth();
      x = Math.min(x, xMax);
      x = Math.max(x, 0);
  
      int y = me.getY() + yAdjustment;
      int yMax = layeredPane.getHeight() - chessPiece.getHeight();
      y = Math.min(y, yMax);
      y = Math.max(y, 0);
  
      chessPiece.setLocation(x, y);
   }
  
  /*
  **  Drop the chess piece back onto the chess board
  */
  public void mouseReleased(MouseEvent e)
  {
      layeredPane.setCursor(null);
  
      if (chessPiece == null) return;
  
      //  Make sure the chess piece is no longer painted on the layered pane
  
      chessPiece.setVisible(false);
      layeredPane.remove(chessPiece);
      chessPiece.setVisible(true);
  
      //  The drop location should be within the bounds of the chess board
  
      int xMax = layeredPane.getWidth() - chessPiece.getWidth();
      int x = Math.min(e.getX(), xMax);
      x = Math.max(x, 0);
  
      int yMax = layeredPane.getHeight() - chessPiece.getHeight();
      int y = Math.min(e.getY(), yMax);
      y = Math.max(y, 0);
  
      Component c =  chessBoard.findComponentAt(x, y);
  
      if (c instanceof JLabel)
      {
          Container parent = c.getParent();
          parent.remove(0);
          parent.add( chessPiece );
          parent.validate();
      }
      else
      {
          Container parent = (Container)c;
          parent.add( chessPiece );
          parent.validate();
      }
  }
  
  public void mouseClicked(MouseEvent e) {}
  public void mouseMoved(MouseEvent e) {}
  public void mouseEntered(MouseEvent e) {}
  public void mouseExited(MouseEvent e) {}
  </code></pre>
  
  <p>jPanelSquare is made of this class:</p>
  
  <pre><code>class JPanelSquare extends JPanel {
  private int rank;
  private int file;
  private JLabel chessPiece = null;
  
  public JPanelSquare(int rank, int file, Color bkgrnd) {
      this.rank = rank;
      this.file = file;
      setBackground(bkgrnd);
      setLayout(new GridBagLayout());
  }
  
  public int getRank() {
      return rank;
  }
  public int getFile() {
      return file;
  }
  
  @Override
  public Component add(Component c) {
      chessPiece = (JLabel)c;
      return super.add(c);
  }
  
  @Override
  public void remove(Component comp) {
      chessPiece = null;
      super.remove(comp);
  }
  
  public JLabel getChessPiece() {
      return chessPiece;
  }
  </code></pre>
  
  <p>}</p>