Issue
I am trying to get anchorpane leftAnchorProperty
to create a new KeyValue
but it is not working.
My code:
Animation a = new Timeline( new KeyFrame(
Duration.seconds(2), new KeyValue(MyAPane.leftAnchorProperty(child), 10)
));
What am I doing wrong?
Solution
There is no such property since the value is stored in the properties
ObservableMap
. (The value is stored there, since only children of a AnchorPane
need it, but there are other layouts a Node
can be added to.)
However in your case you only need a WritableValue
, which you can easily implement yourself:
WritableValue<Double> writable = new WritableValue<Double>() {
@Override
public Double getValue() {
return AnchorPane.getLeftAnchor(child);
}
@Override
public void setValue(Double value) {
AnchorPane.setLeftAnchor(child, value);
}
};
// a starting value for the animation is important, since otherwise interpolation won't work
AnchorPane.setLeftAnchor(child, 0d);
Consider using the translateX
property though. This would be simpler...
Answered By - fabian
Answer Checked By - Marilyn (JavaFixing Volunteer)