code: void ensureValidGridBounds(int colCount, int rowCount) {
          if (gridX <= 0) {
              throw new IndexOutOfBoundsException(
                      "The column index " + gridX + " must be positive.");
          }
          if (gridX > colCount) {
              throw new IndexOutOfBoundsException(
                      "The column index " + gridX + " must be less than or equal to "
                      + colCount + ".");
          }
          if (gridX + gridWidth - 1 > colCount) {
              throw new IndexOutOfBoundsException(
                      "The grid width " + gridWidth + " must be less than or equal to "
                      + (colCount - gridX + 1) + ".");
          }
          if (gridY <= 0) {
              throw new IndexOutOfBoundsException(
                      "The row index " + gridY + " must be positive.");
          }
          if (gridY > rowCount) {
              throw new IndexOutOfBoundsException(
                      "The row index " + gridY + " must be less than or equal to "
                      + rowCount + ".");
          }
          if (gridY + gridHeight - 1 > rowCount) {
              throw new IndexOutOfBoundsException(
                      "The grid height " + gridHeight + " must be less than or equal to "
                      + (rowCount - gridY + 1) + ".");
          }
      }
docs: Checks and verifies that this constraints object has valid grid index values, i. e. the
  display area cells are inside the form's grid.
  
  @param colCount number of columns in the grid
  @param rowCount number of rows in the grid
  @throws IndexOutOfBoundsException if the display area described by this constraints object is
  not inside the grid