Search code examples
javafx-2

Set caret position in javafx.scene.control.TextArea and javafx.scene.control.TextField


I need to set the caret position manually in my code. There is a getCaretPosition() under javafx.scene.control.TextInputControl but there is no setter method.

How can I set the caret position?


Solution

  • TextArea ta = new TextArea();
    ta.setText("1234567890");
    ta.positionCaret(4);