public void start(Stage secondryStage) {
root = new BorderPane();
dialogScene = new Scene(root, 820, 620);
secondryStage.setScene(dialogScene);
secondryStage.show();
root.getChildren().add(createUI());
stageSizeChageListener(secondryStage);
}
private void stageSizeChageListener(Stage stage){
stage.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("Width changed!!");
updateWidth();
}
});
stage.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("Height changed!!");
updateHeight();
}
});
}
public void updateHeight() {
// TODO Auto-generated method stub
double widthPercentChange = (dialogScene.getWidth()/defaultWidth.doubleValue());
double heightPercentChange = (dialogScene.getHeight()/defaultHeight.doubleValue());
secondaryStageBox.setScaleX(heightPercentChange);
secondaryStageBox.setScaleY(heightPercentChange);
}
public void updateWidth(){
double widthPercentChange = (dialogScene.getWidth()/defaultWidth.doubleValue());
double heightPercentChange = (dialogScene.getWidth()/defaultHeight.doubleValue());
secondaryStageBox.setScaleX(widthPercentChange);
secondaryStageBox.setScaleY(widthPercentChange);
}
上面是我的代码,在舞台调整大小时调整secondaryStageBox容器(窗格)的大小,我需要根据secondaryStageBox容器(窗格)按比例调整舞台的高度和宽度,但它不起作用.. secondaryStageBox是一个窗格,它是按比例调整大小,但阶段没有。