title: How do I add an listener to combobox java
body: <p>I am trying to add a listener to my combobox on javafx.<br>
  Here is the code for my combobox:</p>
  
  <pre><code>ObservableList&lt;String&gt; options =
          FXCollections.observableArrayList(
                  "Option1",
                  "Option2",
                  "Option3",
                  "Option4"
          );
  
  final ComboBox comboBox;
  
  public ComboBox getComboBox() {
      return comboBox;
  }
  
  public ComboBoxStatus() {
      this.comboBox = new ComboBox(options);
      comboBox.setValue("option1");
  }
  </code></pre>
  
  <p>and I want to add something like:<br>
  whenever something has been changed like option1 to option2 call a function and do sth</p>
  
  <p>As seen above I have added the default value to <code>option1</code>. So I want to call a function when I change the current value, which is <code>option1</code> as the default value, to e.g. <code>option2</code>.</p>
  
  <p>On my Main programm I have while loop and I would like to read the current selected value from my combobox.</p>
  
  <p>How do I read the current selected value?</p>