@@ -245,11 +245,16 @@ public void resizeComponent(Component component, Integer width, Integer height)
245245 * @param y When defined component's Y value is updated, if null old value is kept
246246 * @param width When defined component's width is updated, if null old value is kept
247247 * @param height When defined component's height is updated, if null old value is kept
248- * @throws IllegalArgumentException If given value are invalid (eg. component is not child of this layout)
248+ * @throws IllegalArgumentException If given value are invalid (eg. component is not child of this layout, or
249+ * coordinates are invalid).
249250 */
250251 public void moveAndResizeComponent (Component component , Integer x , Integer y , Integer width , Integer height )
251252 throws IllegalArgumentException {
252253
254+ if (x != null & width != null && x >= 0 && x + width > getState (false ).gridStackOptions .width ) {
255+ throw new IllegalArgumentException ("Component would go outside the right edge of layout" );
256+ }
257+
253258 GridStackChildOptions info = getState ().childOptions .get (component );
254259 if (info == null ) {
255260 throw new IllegalArgumentException ("Given component is not child of GridStackLayout" );
@@ -605,6 +610,7 @@ public boolean isWrapperScrolling(Component child) {
605610 * @param x Top edge coordinate of area
606611 * @param width Width of area in slots
607612 * @param height Height of area in slots
613+ * @return true if area is available and valid for use
608614 * @throws IllegalArgumentException If invalid values given
609615 */
610616 public boolean isAreaEmpty (int x , int y , int width , int height ) throws IllegalArgumentException {
@@ -613,8 +619,10 @@ public boolean isAreaEmpty(int x, int y, int width, int height) throws IllegalAr
613619
614620 /**
615621 * Check if given area is empty. Remember that any client side defined positioning not yet reported back to
616- * server side will be unknown and so can result work results.
622+ * server side will be unknown and so can result work results. Will also return false if area would go outside the
623+ * right edge.
617624 * @param coordinates Coordinate area checked (x, y, width, height)
625+ * @return true if area is available and valid for use
618626 * @throws IllegalArgumentException If invalid values given
619627 */
620628 public boolean isAreaEmpty (GridStackCoordinates coordinates ) throws IllegalArgumentException {
@@ -631,6 +639,11 @@ public boolean isAreaEmpty(GridStackCoordinates coordinates) throws IllegalArgum
631639 throw new IllegalArgumentException ("Height most be larger than zero" );
632640 }
633641
642+ // If item would drop out of left side, return false
643+ if (coordinates .getX () + coordinates .getWidth () > getState (false ).gridStackOptions .width ) {
644+ return false ;
645+ }
646+
634647 for (int dx = 0 ; dx < coordinates .getWidth (); ++dx ) {
635648 for (int dy = 0 ; dy < coordinates .getHeight (); ++dy ) {
636649 Component occupant = getComponent (coordinates .getX () + dx , coordinates .getY () + dy , true );
0 commit comments