Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 879
Anuruddha Avatar asked Nov 28 '11 09:11

Anuruddha


People also ask

How do you make a text field non editable in JavaFX?

You can use following statement in order to make text-area object non-editable with auto scrollbar: textAreaObjectName. setEditable(false);

What is TextField in JavaFX?

TextField class is a part of JavaFX package. It is a component that allows the user to enter a line of unformatted text, it does not allow multi-line input it only allows the user to enter a single line of text. The text can then be used as per requirement.

What is TextArea in JavaFX?

A JavaFX TextArea control enables users of a JavaFX application to enter text spanning multiple lines, which can then be read by the application. The JavaFX TextArea control is represented by the class javafx. scene.

How do you add a text field in JavaFX?

Creating a Text FieldLabel label1 = new Label("Name:"); TextField textField = new TextField (); HBox hb = new HBox(); hb. getChildren(). addAll(label1, textField); hb. setSpacing(10);


1 Answers

TextArea ta = new TextArea();
ta.setText("1234567890");
ta.positionCaret(4);
like image 198
Sergey Grinev Avatar answered Sep 22 '22 13:09

Sergey Grinev