JavaFX, show canvas on second scree, works well on Windows but not on Linux
Davide Perini
perini.davide at dpsoftware.org
Sat Oct 16 16:41:12 UTC 2021
The strange things is that it works perfectly on Windows but not on Linux.
Is this a JavaFX bug?
I tried to format code better to make it more readable...
Stage stage = new Stage();
Group root = new Group();
Scene s = new Scene(root, 1920, 1080, Color.BLACK);
GraphicsContext gc;
Canvas canvas = new Canvas(1920,1080);
gc = canvas.getGraphicsContext2D();
canvas.setFocusTraversable(true);
// Hide canvas on key pressed
canvas.setOnKeyPressed(t -> {
stage.setFullScreen(false);
stage.hide();
});
drawThings(gc);
root.getChildren().add(canvas);
stage.setScene(s);
// Show canvas on the correct display number
Rectangle2D bounds = Screen.getScreens().get(1).getVisualBounds();
stage.setX(bounds.getMinX());
stage.setY(bounds.getMinY());
stage.show();
stage.setFullScreen(true);
Thanks
Davide
Il 14/10/2021 16:05, Davide Perini ha scritto:
> Hi all,
> I have a small piece of code that shows a canvas with JavaFX.
>
> I want to display the canvas on the second screen.
> This works well in Windows but not on Linux Ubuntu.
>
> Stage stage =new Stage(); Group root =new Group(); Scene s =new
> Scene(root, 1920, 1080, Color.BLACK); GraphicsContext gc; Canvas
> canvas =new Canvas(1920,1080); gc = canvas.getGraphicsContext2D();
> canvas.setFocusTraversable(true); // Hide canvas on key pressed
> canvas.setOnKeyPressed(t -> {
> stage.setFullScreen(false); stage.hide(); }); drawThings(gc);
> root.getChildren().add(canvas); stage.setScene(s); // Show canvas on
> the second display Rectangle2D bounds =
> Screen.getScreens().get(1).getVisualBounds();
> stage.setX(bounds.getMinX()); stage.setY(bounds.getMinY());
> stage.show(); stage.setFullScreen(true);
>
>
>
> On Linux the canvas is shown on the first screen.
> I have tried swapping the screen index from
>
> // Show canvas on the second display Rectangle2D bounds =
> Screen.getScreens().get(1).getVisualBounds();
>
> to
>
> // Show canvas on the second display Rectangle2D bounds =
> Screen.getScreens().get(0).getVisualBounds();
>
> but same problem.
>
> Any idea?
>
> Thank you
> Davide
>
>
>
>
>
>
>
>
More information about the openjfx-dev
mailing list