code: private void layoutChild(
          Component component, int cellX, int cellY, int cellSizeX, int cellSizeY)
      {
          int maxAspectW = (int)(cellSizeY * aspect);
          int maxAspectH = (int)(cellSizeX / aspect);
          
          if (maxAspectW > cellSizeX)
          {
              int w = cellSizeX;
              int h = maxAspectH;
              int space = cellSizeY - h;
              int offset = (int)(alignment * space);
              component.setBounds(cellX, cellY + offset, w, h);
          }
          else
          {
              int w = maxAspectW;
              int h = cellSizeY;
              int space = cellSizeX - w;
              int offset = (int)(alignment * space);
              component.setBounds(cellX + offset, cellY, w, h);
          }
      }
docs: Lay out the given child component inside its parent, obeying
  the aspect ratio and alignment constraints of this layout.
  
  @param component The child component
  @param cellX The (pixel) x-coordinate of the cell inside the parent
  @param cellY The (pixel) y-coordinate of the cell inside the parent
  @param cellSizeX The cell size in x-direction, in pixels
  @param cellSizeY The cell size in y-direction, in pixels