title: JavaFX: Binding Timeline's duration to a property
body: <p>I have an application that has a combobox with some double values. The user can select any of the values. The application has a "<a href="http://docs.oracle.com/javafx/2/api/javafx/animation/Timeline.html" rel="nofollow">TimeLine</a>" attached to it that will print a statement on the console. The <a href="http://sscce.org/" rel="nofollow">sscce</a> is below. What should happen is that is should print the text of the option selected from the combobox. Pls advise.</p>
  
  <pre><code>package just.to.test;
  
  import javafx.animation.KeyFrame;
  import javafx.animation.Timeline;
  import javafx.application.Application;
  import javafx.collections.FXCollections;
  import javafx.collections.ObservableList;
  import javafx.event.ActionEvent;
  import javafx.event.EventHandler;
  import javafx.scene.Group;
  import javafx.scene.Scene;
  import javafx.scene.control.ComboBox;
  import javafx.stage.Stage;
  import javafx.util.Duration;
  
  public class TimerSample extends Application  {
      public static void main(String[] args) {
          Application.launch(args);
      }
  
      @Override
      public void start(Stage primaryStage) {
          primaryStage.setTitle("Text Fonts");
  
          Group g = new Group();
          Scene scene = new Scene(g, 150, 100);
  
          ObservableList&lt;Double&gt; data = FXCollections.observableArrayList();
  
          data.add(5.0);
          data.add(10.0);
          data.add(15.0);
          data.add(20.0);
  
          ComboBox&lt;Double&gt; timeOptions = new ComboBox&lt;Double&gt;(data);
          timeOptions.getSelectionModel().selectFirst();
  
          g.getChildren().addAll(timeOptions);
  
          primaryStage.setScene(scene);
          primaryStage.show();
  
          final double timerInterval = timeOptions.getSelectionModel().getSelectedItem();
  
          KeyFrame keyFrame = new KeyFrame(Duration.seconds(timerInterval),
              new EventHandler&lt;ActionEvent&gt;() {
                  @Override
                  public void handle(ActionEvent event) {
                      System.out.println("This is called every "
                          + timerInterval + " seconds");
                  }
              });
  
          Timeline timerThread = new Timeline(keyFrame);
          timerThread.setCycleCount(Timeline.INDEFINITE);
          timerThread.play();
      }
  }
  </code></pre>