void (Rectangle targetBounds) { Point topLeft = new Point(targetBounds.x, targetBounds.y); Point bottomRight = new Point((int)targetBounds.getMaxX(), (int)targetBounds.getMaxY()); Rectangle topLeftScreen = ScreenUtil.getScreenRectangle(topLeft); Rectangle bottomRightScreen = ScreenUtil.getScreenRectangle(bottomRight); if (topLeft.x < topLeftScreen.x || topLeft.y < topLeftScreen.y || bottomRight.x > bottomRightScreen.getMaxX() || bottomRight.y > bottomRightScreen.getMaxY()) { GraphicsDevice device = ScreenUtil.getScreenDevice(targetBounds); Rectangle mostAppropriateScreenRectangle = device != null ? ScreenUtil.getScreenRectangle(device.getDefaultConfiguration()) : ScreenUtil.getMainScreenBounds(); ScreenUtil.moveToFit(targetBounds, mostAppropriateScreenRectangle, null); } }