How do I switch between fullscreen and windowed during the sketch

So as the title says, I want to create a button or something that I can click during a sketch to resize the window from fullscreen to different windowed resolutions like in a game.

I’ve experimented with surface.setSize(), surface.setResizable(true) etc, but after a ton of googling I still can’t find a way to switch between windowed and fullscreen during the sketch.

Is this a limitation of Processing or am I just missing something here?

Any help is greatly appreciated

In FX2D renderer mode…

First expose the JavaFX stage:

private final surface = (PSurfaceFX) getSurface();
private final canvas = (Canvas) surface.getNative();
private final stage = (Stage) canvas.getScene().getWindow();
stage.setFullScreenExitHint(""); // disable fullscreen toggle hint

Then use this code to toggle fullscreen:

noLoop();
stage.setFullScreen(!stage.isFullScreen());
loop();

This is the approach we are using to toggle fullscreen in this open source Processing game.

1 Like