title: How to move the cursor position in a JTextField
body: <p>I have a <code>JTextField inputTextField</code> and I would like the symbol <code>∨</code> to be added to the text field at the cursor position when the <code>orButton</code> is pressed. The method below works but after the button is pressed the cursor appears at the end of the field instead of at the position it was before the button is pressed.</p>
  
  <p>How can I set the cursor to move back to its previous position?</p>
  
  <pre><code>private void orButtonActionPerformed(java.awt.event.ActionEvent evt)                                          
      {
          int caretPosition = inputTextField.getCaretPosition();
          String currentText = inputTextField.getText();
          String newText = currentText.substring(0, caretPosition) + 
          "∨" + currentText.substring(caretPosition, currentText.length());
  
          inputTextField.setText(newText);
          inputTextField.requestFocus();
      }                                        
  </code></pre>
  
  <p>I thought <code>setCaretPosition()</code> might be what I was looking for but it didn't work.</p>