private void shiftComponentsHorizontally ( int columnIndex , boolean remove ) { final int offset = remove ? - 1 : 1 ; for ( Object element : constraintMap . entrySet ( ) ) { Map . Entry entry = ( Map . Entry ) element ; CellConstraints constraints = ( CellConstraints ) entry . getValue ( ) ; int x1 = constraints . gridX ; int w = constraints . gridWidth ; int x2 = x1 + w - 1 ; if ( x1 == columnIndex && remove ) { throw new IllegalStateException ( "The removed column " + columnIndex + " must not contain component origins.\n" + "Illegal component=" + entry . getKey ( ) ) ; } else if ( x1 >= columnIndex ) { constraints . gridX += offset ; } else if ( x2 >= columnIndex ) { constraints . gridWidth += offset ; } } }
Shifts components horizontally either to the right if a column has been inserted or to the left if a column has been removed .