Animation‎ > ‎

Animate Size


The JavaFX Transition API lets you quickly create animation sequences based on object properties.  The following code shows how to animate an object's scale using the ScaleTransition class:

def w = 400;
def h = 200;
def r = 50;

def circle = Circle {
            centerX: w / 2;
            centerY: h / 2;
            radius: r
            fill: Color.BLUE;
            stroke: Color.WHITE;
            strokeWidth: 3
        }

ScaleTransition {
    node: circle
    duration: 3s
    fromX:0.5 fromY:0.5
    toX:3 toY:3
    repeatCount: FadeTransition.INDEFINITE autoReverse: true
}.playFromStart();

See Animation
When the code execute, you will see the circle being moved from one corner to another.  
Click here to see animation.


The materials on this website represent a small sample of content loosely based on the book JavaFX Application Development Cookbook.  The book offers far more content with over 80 recipes covering a range of topics from basics to advanced concepts.  

Buy the Book

You can get your copy of the book directly from the publisher. Click here to order!