ObservableList<Screen> screensForRectangle = Screen.getScreensForRectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
Screen screen = screensForRectangle.get(0);
Rectangle2D visualBounds = screen.getVisualBounds();
// Dock Left
if (mouseEvent.getScreenX() == visualBounds.getMinX()) {
savedBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
stage.setX(visualBounds.getMinX());
stage.setY(visualBounds.getMinY());
// Respect Stage Max size
double width = visualBounds.getWidth() / 2;
if (stage.getMaxWidth() < width) {
width = stage.getMaxWidth();
}
stage.setWidth(width);
double height = visualBounds.getHeight();
if (stage.getMaxHeight() < height) {
height = stage.getMaxHeight();
}
stage.setHeight(height);
undecorator.setShadow(false);
} // Dock Right (visualBounds = [minX = 1440.0, minY=300.0, maxX=3360.0, maxY=1500.0, width=1920.0, height=1200.0])
else if (mouseEvent.getScreenX() >= visualBounds.getMaxX() - 1) { // MaxX returns the width? Not width -1 ?!
savedBounds = new BoundingBox(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
stage.setX(visualBounds.getWidth() / 2 + visualBounds.getMinX());
stage.setY(visualBounds.getMinY());
// Respect Stage Max size
double width = visualBounds.getWidth() / 2;