enter image description here Found only getCaretPosition (), but this is a bit wrong.

    1 answer 1

    If you look at the TextFieldSkin class, it inherits from TextInputControlSkin . It contains an instance of the Path class, which shows the cursor, caretPath . But it is declared with the protected modifier.

     protected final Path caretPath = new Path(); 

    To gain access to it, you need to create a successor. In it we will get access to our cursor. And with each change of the cursor we will catch it and process it.

     import com.sun.javafx.scene.control.skin.TextFieldSkin; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Bounds; import javafx.geometry.Point2D; import javafx.scene.control.TextField; import javafx.stage.Stage; public class TextFieldCaretControlSkin extends TextFieldSkin { public TextFieldCaretControlSkin(TextField textField, Stage stage) { super(textField); // слСдим Π·Π° измСнСниями layoutBoundProperty нашСго экзСмпляра Path caretPath.layoutBoundsProperty().addListener(new ChangeListener<Bounds>() { @Override public void changed(ObservableValue<? extends Bounds> observable, Bounds oldValue, Bounds newValue) { // ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Ρ‹ курсора ΠΎΡ‚Π½ΠΎΡΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎ TextField-Π° double x = newValue.getMaxX(); double y = newValue.getMaxY(); // искомая ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Π°Ρ‚Π° Point2D p = caretPath.localToScene(x, y); System.out.println(p.toString()); } }); } } 

    The same way you can get the coordinates of the cursor from all TextInputControlSkin .

    • After finding the location of the cursor, you can add different Popup s, add animations, etc. next to the cursor. - catscoolzhyk