2012-12-15 14 views
1

是否可以在Rectangle类中创建类似于 的双属性DoubleProperty xProperty()左上角但定义了右下角的X坐标?JavaFx 2.x:右下角的矩形定制属性

对Y坐标同样存在问题。

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

感谢

回答

2

你可以做到以下几点,这应该解决这个问题。

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

otherProperty.bind(maxX); 
anotherProperty.bind(maxY); 

但是,因为这些属性是计算出来的,所以不能在bindBidirectional中使用它们。原因是如果otherProperty设置不同的值为maxXJavaFX无法计算出哪个xPropertywidthProperty发生更改。您需要为此创建自己的属性,具体取决于您希望otherProperty的更改如何影响xPropertywidthProperty

+0

嗨Hbcdev感谢您的回复 –