title: JavaFX: ProgressBar with timeline; reset both if completed
body: <p>I am building an application which is an exam. All the questions are shown on different screens, all with a progressbar showing how much time the user has left.
  When the progressbar is full, the screen with another question is shown and the progressbar and timeline should be resetted.</p>
  
  <p>When the time is up, the next screen is shown and the timeline resets, but the progressbar (shown in code as 'PRGB') remains full and it will not reset to an empty progressbar. This is my code:</p>
  
  <pre><code>public void timeBar() throws Exception{
      Timeline timeline = new Timeline(
              new KeyFrame(Duration.ONE, new KeyValue(PRGB.progressProperty(), 0)),
              new KeyFrame(Duration.seconds(Main.time), e-&gt; {
              }, new KeyValue(PRGB.progressProperty(), 1))
      );
      timeline.setCycleCount(1);
      timeline.play();
      timeline.setOnFinished(event -&gt; {
          Main.setPane(questionNumber);
          questionNumber++;
          timeline.play();
          //in here the progressbar has to be resetted
      });
  }
  </code></pre>
  
  <p><strong>Update:</strong>
  I have deleted my ProgressBar from SceneBuilder, and made a new one on which I then run the code below (with a few alterations taking by your suggestions). But now the progressbar does reset it self, but it does not show the progress: it stays empty. </p>
  
  <pre><code>public void timeBar() throws Exception{
      Timeline timeline = new Timeline(
              //I only use two keyframes instead of three
              new KeyFrame(Duration.seconds(Main.time), e-&gt; {
              }, new KeyValue(PRGB.progressProperty(), 1))
      );
      timeline.setCycleCount(1);
      timeline.play();
      timeline.setOnFinished(event -&gt; {
          Main.setPane(questionNumber);
          questionNumber++;
          //The setProgress is added
          PRGB.setProgress(0.0F);
          timeline.play();
      });
  }
  </code></pre>