Question on scene.setRoot vs stage.setScene

Nir Lisker nlisker at
Mon May 18 21:51:59 UTC 2020

Hi Paul,

Metaphors aside, I would say it depends on the use case. If you are making
a change only on the scene graph, then there is no need to change the
scene. A scene has many properties of its own that control its behavior and
visuals. You can create a scene with a depth buffer, for example, and if
you want to use a scene without a depth buffer then you would need to swap
the scene itself. As a rule of thumb, try to change the minimum that you
can. If you want to change the text of a button, would you just change the
text or create a new button with a different text?

I have noticed that calling stage.setScene appears to resize the stage

This is stated in the docs of Stage#sceneProperty: "If the width or height
of this Window have never been set by the application, setting the scene
will cause this Window to take its width or height from that scene.", so it
shouldn't be surprising.

- Nir

On Mon, May 18, 2020 at 11:40 AM Paul Johnson <paul at> wrote:

> I'm currently evaluating JavaFX for a project and I'm pretty confused by
> recommendations on stack-overflow and also by the JavaFX archetype on
> Maven which seem to suggest that when altering content on a stage one
> should switch out the scene graphs root node instead of replacing the
> the current scene, I have yet to find an explanation as to why that
> should be the case.
> Does this not mean that the theatre metaphor is fundamentally broken?
> This theatre has a primary stage, the show has only one scene to act out
> on the primary stage but the props and actors of the scene are changed
> so radically that it appears to the audience that there are multiple
> scenes taking place.
> I have noticed that calling stage.setScene appears to resize the stage
> which also seems to break the metaphor, presumably those dressing the
> stage / acting should adapt the setup to the stage rather than resizing
> the stage to accommodate the scene.
> Kind regards
> Paul

More information about the openjfx-discuss mailing list