如标题所示,Window.xProperty()
和 Window.yProperty()
均定义为 ReadOnlyDoubleProperty
。但是,有 Window.setX()
和 Window.setY()
允许我们设置值。这样设计有什么原因吗?
最佳答案
这在 documentation of Stage
中有解释。 :
Many of the
Stage
properties are read only because they can be changed externally by the underlying platform and therefore must not be bindable.
虽然这是针对 Stage
进行说明的,但推理适用于 Window
的某些属性。以及。事实上,诸如 width
、height
和 focused
之类的属性都提到了同一件事:
The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.
我不知道为什么 x
和 y
属性在其文档中没有这句话,尽管我猜这只是一个疏忽。
关于JavaFX:为什么当有 setter 时 Window.xProperty() 和 Window.yProperty() 是只读的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53277912/