I read the book, but I am still confused about pause transition methods. I made a label showing number, and I want that number to be increased in every second.
相关问题
- I get an exception when trying to swap elements in
- JFX scale image up and down to parent
- Dragging an undecorated Stage in JavaFX
- JavaFX sample issue
- How to change the font size in ListView in JavaFX?
相关文章
- Low quality icon in taskbar of a Stage. JavaFX
- Loading custom font using JavaFX 8 and css
- Javafx Platform.runLater never running
- JavaFX scrolling table update performance degrades
- Javafx select multiple rows
- Escape from a Number TextField in a JavaFX dialog
- How to merge cells in JavaFX Scene builder?
- Adding view with constructor arguments to a border
How to use a PauseTransition
A PauseTransition is for a one off pause. The following sample will update the text of a label after a one second pause:
Why a PauseTransition is not for you
But this isn't what you want to do. According to your question, you want to update the label every second, not just once. You could set the pause transition to cycle indefinitely, but that wouldn't help you because you can't set an event handler on cycle completion in JavaFX 8. If a PauseTransition is cycled indefinitely, the finish handler for the transition will never be called because the transition will never finish. So you need another way to do this...
You should use a Timeline
As suggested by Tomas Mikula, use a Timeline instead of a PauseTransition.
Alternate solution with a Timer
There is an alternate solution based on a Timer for the following question:
However, I prefer the Timeline based solution to the Timer solution from that question. The Timer requires a new thread and extra care in ensuring updates occur on the JavaFX application thread, and the Timeline based solution does not require any of that.
As commented by Adowarth :