How to listen for resize events in JavaFX

前端 未结 3 859
野趣味
野趣味 2020-12-09 04:11

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

3条回答
  •  执笔经年
    2020-12-09 05:12

    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

提交回复
热议问题