Finding the cursor text position in JTextField

caret, java, jspinner, swing

Solution

`JTextField.getCaretPosition()`

`JTextField.setCaretPosition(int pos)`

Problem

Is there a method to return the position of the character in the JTextField. What I mean by that is if I have a JTextField with some values in it. For example, the field contains value ABCDEFJ. The user decides to put the cursor right after the character 'C' to enter a new value. Is there a method to get position where he enters the new character. In this example, that would return a 3.

Original source