Rectangle (ComponentDragObject dragObject, boolean spans) { int firstRow = getRow(); int lastRow = getRow(); int firstCol = getColumn(); int lastCol = getColumn(); for (int i = 0; i < dragObject.getComponentCount(); i++) { int relRow = dragObject.getRelativeRow(i); int relCol = dragObject.getRelativeCol(i); firstRow = Math.min(firstRow, getRow() + relRow); firstCol = Math.min(firstCol, getColumn() + relCol); lastRow = Math.max(lastRow, getRow() + relRow + (spans ? dragObject.getRowSpan(i) : 1) - 1); lastCol = Math.max(lastCol, getColumn() + relCol + (spans ? dragObject.getColSpan(i) : 1) - 1); } return new Rectangle(firstCol, firstRow, lastCol - firstCol + 1, lastRow - firstRow + 1); }