title: How to enabled up/down keys in a JavaFX Spinner component
body: <p>I'm using a Spinner component in my JavaFX application. It's created via FXML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Spinner fx:id="spinner" editable="true" min="0" max="100"
           initialValue="3" /&gt;
  </code></pre>
  
  
  
  <p>According to the documentation of <a href="https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Spinner.html" rel="nofollow">Spinner</a>:</p>
  
  <blockquote>
    <p>The keyboard up/down arrow keys also cycle through the elements.</p>
  </blockquote>
  
  <p>However, when I click in the spinner component and press UP or DOWN only the cursor position in the text field changes but not the spinner value.</p>
  
  <p>Is it possible to let the spinner component react on UP and DOWN as described in the JavaDoc?</p>
  
  <p>I already tried to add a key listener to do this job:</p>
  
  <pre class="lang-java prettyprint-override"><code>spinner.setOnKeyPressed(event -&gt; {
      switch (event.getCode()) {
          case UP:
              spinner.increment(1);
              break;
          case DOWN:
              spinner.decrement(1);
              break;
      }
  });
  </code></pre>
  
  
  
  <p>However, this listener is only called when I press UP or DOWN in combination with the control key, which is not very intuitive.  Is there a solution without such a key combination?</p>