-
November 6th, 2018, 11:50 AM
#1
How to animate a button with Timeline?
Hello!
I want to animate a button. I want to make it change its position after clicking on it. I wrote such code, but it does not work. In this case, no errors appear in the console. The button simply does not respond to pressing.
Code:
double stopPosition = 100;
KeyValue kk2 = new KeyValue(btn.layoutXProperty(), stopPosition, Interpolator.LINEAR);
KeyFrame kk = new KeyFrame(Duration.millis(5000),kk2);
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(kk);
timeline.setCycleCount(1);
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
timeline.play();
}
});
What am I doing wrong?
-
November 9th, 2018, 09:54 AM
#2
Re: How to animate a button with Timeline?
Can you make a small, complete program that compiles, executes and shows the problem?
Norm
-
December 10th, 2018, 05:23 AM
#3
Re: How to animate a button with Timeline?
I think the button in some layout that takes care of positioning. If you modify layoutX this means during the next layout pass the Button is simply put back "where it belongs" by the parent layout.
If you want to move the Button, you should choose a different layout as parent or use the translateX property instead. translateX moves the Button relative to the position where the parent layout places it (layoutX).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|