JavaFX Bind Label textProperty更改为多个属性

GOX*_*LUS 2 java binding javafx

我想做的是:

我有一个JavaFX窗口,我通过拖动不断更改它的宽度和高度corners or the sides。I want when the width or height are changing那么的文本Label将具有以下格式:

~Width=[here the width of the Window],Height[here the height of the Window]~
Run Code Online (Sandbox Code Playgroud)

例:

~Width=[1300],Height=[600]~
Run Code Online (Sandbox Code Playgroud)

我想使用绑定而不是2(two)来做到这一点ChangeListeners。

                                   I am trying:

label.textProperty().bind(I am stack here on how to do this...);
Run Code Online (Sandbox Code Playgroud)

我也读过这个问题JavaFX绑定到多个属性

fab*_*ian 6

只要使用Bindings.createStringBinding既width和height为依赖关系:

StringBinding binding = Bindings.createStringBinding(
            () -> MessageFormat.format("~Width=[{0}],Height=[{1}]~", primaryStage.getWidth(), primaryStage.getHeight()),
            primaryStage.widthProperty(),
            primaryStage.heightProperty());

label.textProperty().bind(binding);
Run Code Online (Sandbox Code Playgroud)