java - How to animate dashed line Javafx -


i want move (animate) dashes in line:

  line l=new line();   l.getstrokedasharray().addall(25d, 20d, 5d, 20d); 

animate stokedashoffsetproperty of line value of 0 until total length of items in stroke dash array. run timeline in reverse if want animate in opposite direction.

offset1 offset2

import javafx.animation.*; import javafx.application.application; import javafx.scene.*; import javafx.scene.shape.line; import javafx.stage.stage; import javafx.util.duration;  public class linestrokeanimator extends application {     @override public void start(stage stage) {         line line = new line(20, 100, 80, 20);         line.getstrokedasharray().setall(25d, 20d, 5d, 20d);         line.setstrokewidth(2);          final double maxoffset =                  line.getstrokedasharray().stream()                         .reduce(                                 0d,                                  (a, b) -> + b                         );          timeline timeline = new timeline(                 new keyframe(                         duration.zero,                          new keyvalue(                                 line.strokedashoffsetproperty(),                                  0,                                  interpolator.linear                         )                 ),                 new keyframe(                         duration.seconds(2),                          new keyvalue(                                 line.strokedashoffsetproperty(),                                  maxoffset,                                  interpolator.linear                         )                 )         );         timeline.setcyclecount(timeline.indefinite);         timeline.play();          stage.setscene(new scene(new group(line), 100, 120));         stage.show();     }      public static void main(string[] args) {         launch(args);     } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -