我想做的是:
我有一个 JavaFX 窗口,我通过拖动角或边
不断改变它的宽度和高度。我想要宽度或高度改变时
然后 Label
的文本具有以下格式:
~Width=[here the width of the Window],Height[here the height of the Window]~
例子:
~Width=[1300],Height=[600]~
我想使用绑定(bind)而不是使用 2(两个)ChangeListeners
来做到这一点。
I am trying:
label.textProperty().bind(I am stack here on how to do this...);
最佳答案
只需将 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);
关于JavaFX 将标签文本属性绑定(bind)到多个属性更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41571519/