Pedro Duque Vieira pedro.duquevieira at gmail.com
Tue Mar 6 14:16:34 PST 2012

I use both javax.swing.timer and Timeline, everything works perfect.

Pedro Duque Vieira

On Mar 6, 2012, at 10:41 AM, Tom Eugelink wrote:

>* *>* All I can say; using timeline I had all kinds of quircks, and the util Timer worked in the first attempt.*>* *>* Tom*>* *>* *>* *>* On 2012-03-06 19:29, Richard Bair wrote:*>>* ScrollBarBehavior uses a Timeline for this same kind of functionality. I don't know if I'm understanding what the problem is with using a Timeline for this, although using a java.util.Timer and Platform.runLater sounds pretty easy too.*>>* *>>* *>>* timeline = new Timeline();*>>*         timeline.setCycleCount(Timeline.INDEFINITE);*>>* *>>*         final KeyFrame kf1 = new KeyFrame(*>>*             Duration.millis(0),*>>*             new EventHandler<ActionEvent>() {*>>*                 @Override*>>*                 public void handle(ActionEvent event) {*>>*                     boolean i = (pos>  ((bar.getValue() - bar.getMin())/(bar.getMax() - bar.getMin())));*>>*                     if (incrementing == i) {*>>*                         // we started incrementing and still are, or we*>>*                         // started decrementing and still are*>>*                         bar.adjustValue(pos);*>>*                     }*>>*                     else if (timeline != null) {*>>*                         // we've gone to far! just stop already*>>*                         timeline.stop();*>>*                         timeline = null;*>>*                     }*>>*                 }*>>*             }*>>*         );*>>*         final KeyFrame kf2 = new KeyFrame(Duration.millis(200));*>>*         timeline.getKeyFrames().addAll(kf1, kf2);*>>*         timeline.play();*>>* *>>* On Mar 6, 2012, at 4:25 AM, Michael Heinrichs wrote:*>>* *>>>* Yes, all classes that inherit from Animation have a delay property (a Duration). The delay will only be considered at the very start of an animation and not during looping. Use only one KeyFrame for the loop duration. So for example if you have a delay of 500ms and a KeyFrame at 100ms, you will get notifications like this:*>>>* 600ms 700ms 800ms...*>>>* *>>>* - Michael*>>>* *>>>* *>>>* On 06.03.2012, at 13:05, Tom Eugelink wrote:*>>>* *>>>>* I have been pondering this as well, but would this do the initial delay and the quick repeat afterwards? Or should I use the first KeyFrame for the initial delay and a second KeyFrame for the repeat delay (which just jumps the timeline back to the first). I could wrap this into a real timer class then.*>>>>* *>>>>* *>>>>* On 6-3-2012 11:56, Michael Heinrichs wrote:*>>>>>* Hi Tom,*>>>>>* *>>>>>* I think you can either use a standard Timer or a Timeline with a single KeyFrame and cycleCount INDEFINITE. Your logic needs to go into the onFinished handler. There is a property in Timeline to set an initial delay.*>>>>>* *>>>>>* - Michael*>>>>>* *>>>>>* *>>>>>* On 06.03.2012, at 11:44, Tom Eugelink wrote:*>>>>>* *>>>>>>* For the second time I'm in need of a timer logic, similar to Swing's timer class.*>>>>>>* *>>>>>>* What I want to do is that when there is a mouse-pressed event, a timer is started with an initial delay of 500 ms or s,o and then it must repeat every 100 or 200 ms and increment a value. Real world: the user presses-and-holds the LMB over an arrow in the spinner control, and it must start incrementing; tak tak tak tak tak, maybe picking up speed or step size as the button is held.*>>>>>>* *>>>>>>* There is AFAIK no timer class in JavaFX. There is an AnimationTimer, but that is closely linked to the repaint frequency, this usage should not be.*>>>>>>* *>>>>>>* The other time I needed a timer, all I needed was a single delayed execution, so I abused the PauseTransition and the onFinished event. But now I need the repeating behavior and Animations do not have an onTrigger or something.*>>>>>>* *>>>>>>* What is the best way to do a Swing like timer in JavaFX?*>>>>>>* *>>>>>>* Tom*>>>>* *>>* *>* *>* *

More information about the openjfx-dev mailing list