StrokeTransition based animation
import javafx.animation.StrokeTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Main extends Application {
@Override
public void start(Stage stage) {
final Group group = new Group();
Scene scene = new Scene(group, 300, 150);
stage.setScene(scene);
stage.setTitle("Sample");
Rectangle rect = new Rectangle (100, 40, 100, 100);
rect.setArcHeight(50);
rect.setArcWidth(50);
rect.setFill(null);
StrokeTransition st = new StrokeTransition(Duration.millis(3000), rect, Color.RED, Color.BLUE);
st.setAutoReverse(true);
st.play();
group.getChildren().add(rect);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Related examples in the same category