How to dynamically change scene height in JavaFx

Is it possible to create a Stage in JavaFx whose height changes dynamically? Or, in other words, is it possible to change the height of the scene after creating it ( stage.show()

) so that the scene changes to the new height?

+1


source to share


1 answer


Use stage.sizeToScene () to resize the stage to whatever the current preferred size of this root is.

 stage.setScene(new Scene(someContent));
 stage.show();
 ....
 stage.getScene().setRoot(someNewContent));
 stage.sizeToScene();

      



You can also just call stage.setWidth () or stage.setHeight () if you don't need the automatic sizing behavior sizeToScene()

.

You can use the Timeline to animate the resizing of the scene if you need to.

+4


source







All Articles