JavaFX Stage resizing - Strange behaviour

亡梦爱人 提交于 2020-01-26 00:55:53

问题


Consider the following JavaFx code running on JDK8:

/*Imports*/
public class StageResizing extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage){
        stage.setScene(new Scene(new BorderPane(new Text("Text here.")), 200, 200));

        stage.widthProperty().addListener((ObservableValue<? extends Number> ov, Number t, Number t1) -> {
            stage.setHeight(t1.doubleValue());
        });
        stage.heightProperty().addListener((ObservableValue<? extends Number> ov, Number t, Number t1) -> {
            stage.setWidth(t1.doubleValue());
        });

        stage.show();
    }
}

It is intended to resize the width whenever the height is resized and vice-versa. (I believe setting a observable value to its own value wont trigger a ChangeEvent, right? )

The funny business is the when I resize the window from the corners, botton or top, it works as expected. But resizing from the right side of the windows won't change nothing and the left size will move the window with the same size instead.

Is there any specific reason or error in the code for this to happen?

Appreciate the attention.

来源:https://stackoverflow.com/questions/27835898/javafx-stage-resizing-strange-behaviour

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!