Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen for resize events in JavaFX

Tags:

javafx-2

How can I detect when a Scene or Stage changes size in JavaFX 2.1? I cannot find any EventHandler for this.

like image 410
Kretep Avatar asked May 27 '12 09:05

Kretep


1 Answers

There are heightProperty and widthProperty. You can use these properties for binding, or add listeners to them.

public void start(Stage stage) {
    Scene scene = new Scene(new Group(), 300, 200);
    stage.setScene(scene);

    stage.titleProperty().bind(
            scene.widthProperty().asString().
            concat(" : ").
            concat(scene.heightProperty().asString()));

    stage.show();
}

Or see next example: https://stackoverflow.com/a/9893911/1054140

like image 191
Sergey Grinev Avatar answered Sep 21 '22 22:09

Sergey Grinev