Help test the behavior of a multi-screen setup with both Mac and Windows

Thiago Milczarek Sayão thiago.sayao at gmail.com
Wed Apr 9 10:55:39 UTC 2025


Hi,

Could anyone with a multi-screen setup on Mac and/or Windows please share
the results of the two buttons on this sample app? Your feedback would be
greatly appreciated!

On Ubuntu 24.04 the first button moves the Stage to the end of the first
screen (bit weird).
The second work as expected, it gets moved to the start of the center of
the last screen.

Thanks!

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;
import javafx.stage.StageStyle;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

import java.util.Comparator;

public class TestScreenBounds extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("Move Outside Bounds");
        Rectangle2D bounds = Screen.getScreens().stream()
                .map(Screen::getBounds)

.sorted(Comparator.comparingDouble(Rectangle2D::getMaxX).reversed())
                .findFirst()
                .orElseThrow();

        Button btn = new Button("Move To " + bounds.getMaxX());
        btn.setOnAction(event -> stage.setX(bounds.getMaxX()));

        double middleLastScreen = bounds.getMinX() + bounds.getWidth() / 2;

        Button btn2 = new Button("Move To " + middleLastScreen);
        btn2.setOnAction(event -> stage.setX(middleLastScreen));

        VBox root = new VBox(btn, btn2);
        root.setFillWidth(true);
        root.setAlignment(Pos.CENTER);
        Scene scene = new Scene(root, 300, 300);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(TestScreenBounds.class, args);
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20250409/dc77cadc/attachment-0001.htm>


More information about the openjfx-dev mailing list