void (CaptionSelection selection) { FormLayout layout = (FormLayout) selection.getContainer().getLayout(); int[][] oldGroups = selection.isRow() ? layout.getRowGroups() : layout.getColumnGroups(); int[][] newGroups = new int[oldGroups.length + 1][]; System.arraycopy(oldGroups, 0, newGroups, 0, oldGroups.length); int[] cellsToGroup = getCellsToGroup(selection); newGroups [oldGroups.length] = new int [cellsToGroup.length]; for(int i=0; i<cellsToGroup.length; i++) { newGroups [oldGroups.length] [i] = cellsToGroup [i]+1; } if (selection.isRow()) { layout.setRowGroups(newGroups); } else { layout.setColumnGroups(newGroups); } }