Properties javafx2.x:右下角的矩形自定义属性

Properties javafx2.x:右下角的矩形自定义属性,properties,javafx,shape,Properties,Javafx,Shape,在Rectangle类中是否可以创建类似的doubleproperty DoubleProperty xProperty()左上角,但它定义了右下角的X坐标 Y坐标也有同样的问题 这些新属性应该能够作为参数传递给方法BindDirective 谢谢您可以执行以下操作,这将解决此问题 DoubleBinding maxX = rectangle.xProperty().add(rectangle.widthProperty()); DoubleBinding maxY = rectangle.yP

在Rectangle类中是否可以创建类似的doubleproperty DoubleProperty xProperty()左上角,但它定义了右下角的X坐标

Y坐标也有同样的问题

这些新属性应该能够作为参数传递给方法BindDirective


谢谢

您可以执行以下操作,这将解决此问题

DoubleBinding maxX = rectangle.xProperty().add(rectangle.widthProperty());
DoubleBinding maxY = rectangle.yProperty().add(rectangle.heightProperty());

otherProperty.bind(maxX);
anotherProperty.bind(maxY);
但是,因为这些属性是计算出来的,所以不能在BindDirective中使用它们。原因是如果
otherProperty
maxX
JavaFX
设置了不同的值,则无法确定要更改
xProperty
widthProperty
中的哪一个。为此,您需要创建自己的属性,具体取决于您希望
otherProperty
中的更改如何影响
xProperty
widthProperty