CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: How to animate a button with Timeline?

  1. #1
    Join Date
    Nov 2018

    How to animate a button with Timeline?


    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.

    double stopPosition = 100;
    KeyValue kk2 = new KeyValue(btn.layoutXProperty(), stopPosition, Interpolator.LINEAR);
    KeyFrame kk = new KeyFrame(Duration.millis(5000),kk2);
    Timeline timeline = new Timeline();
            btn.setOnAction(new EventHandler<ActionEvent>() {
                public void handle(ActionEvent event) {
                    System.out.println("Hello World!");
    What am I doing wrong?

  2. #2
    Join Date
    Jun 1999
    Eastern Florida

    Re: How to animate a button with Timeline?

    Can you make a small, complete program that compiles, executes and shows the problem?

  3. #3
    Join Date
    Dec 2018

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)