2016-07-06 19 views

Trả lời

17

Bạn có thể nghe những thay đổi của widthPropertyheightProperty của Stage:

stage.widthProperty().addListener((obs, oldVal, newVal) -> { 
    // Do whatever you want 
}); 

stage.heightProperty().addListener((obs, oldVal, newVal) -> { 
    // Do whatever you want 
}); 

Lưu ý: Để nghe cả chiều rộng và chiều cao thay đổi, người nghe tương tự có thể được sử dụng thực sự chỉ cần:

ChangeListener<Number> stageSizeListener = (observable, oldValue, newValue) -> 
    System.out.println("Height: " + stage.getHeight() + " Width: " + stage.getWidth()); 

stage.widthProperty().addListener(stageSizeListener); 
stage.heightProperty().addListener(stageSizeListener); 
Các vấn đề liên quan