JavaFX: Why are Window.xProperty() and Window.yProperty() read only when there are setters?

Viewed 86

As the title suggests, Window.xProperty() and Window.yProperty() are both defined as ReadOnlyDoubleProperty. However, there are Window.setX() and Window.setY() that allow us to set the values. Is there any reason why it is designed this way?

2 Answers

This is explained in the 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.

While this is stated for Stage the reasoning applies to some of the properties of Window as well. In fact, properties like width, height, and focused all mention the same thing:

The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

I don't know why the x and y properties don't also have this sentence in their documentation, though I'd guess it's just an oversight.

xProperty() and yProperty() return a Property object which contains the value of x and y respectively. setX() and setX() change x and y, not the Property objects.

Related