GridLayoutManager (final RadComponent[] selection, final boolean isVertical) { Arrays.sort( selection, (o1, o2) -> { final Rectangle bounds1 = o1.getBounds(); final Rectangle bounds2 = o2.getBounds(); if (isVertical) { return (bounds1.y + bounds1.height / 2) - (bounds2.y + bounds2.height / 2); } else { return (bounds1.x + bounds1.width / 2) - (bounds2.x + bounds2.width / 2); } } ); for (int i = 0; i < selection.length; i++) { final RadComponent component = selection[i]; final GridConstraints constraints = component.getConstraints(); if (isVertical) { constraints.setRow(i); constraints.setColumn(0); } else { constraints.setRow(0); constraints.setColumn(i); } constraints.setRowSpan(1); constraints.setColSpan(1); } final GridLayoutManager gridLayoutManager; if (isVertical) { gridLayoutManager = new GridLayoutManager(selection.length, 1); } else { gridLayoutManager = new GridLayoutManager(1, selection.length); } return gridLayoutManager; }