I would like to implement a text input using javafx. The cursor looks like a black rectangle (for people with low vision). It seems impossible with a text area or a text field. The mouse shape can be an arrow for example. Can you give ideas to implement this function ?
Asked
Active
Viewed 496 times
1
-
I have not tested [this](https://github.com/thejeed/javafx-caret-example/tree/master/src/java/de/jeed/caretexample), but [this](https://github.com/thejeed/javafx-caret-example/tree/master/src/java/de/jeed/caretexample) project seems to change the color and width. – SedJ601 Dec 18 '17 at 20:48
1 Answers
1
import com.sun.javafx.scene.control.skin.TextFieldSkin;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class CaretColorizer extends Application {
@Override
public void start(Stage stage) throws Exception {
TextField redCaretTextField = new TextField("Big black caret");
redCaretTextField.setSkin(
new TextFieldCaretControlSkin(
redCaretTextField,
Color.RED
)
);
VBox layout = new VBox(10, redCaretTextField);
layout.setPadding(new Insets(10));
stage.setScene(new Scene(layout));
stage.show();
}
public class TextFieldCaretControlSkin extends TextFieldSkin {
public TextFieldCaretControlSkin(TextField textField, Color caretColor) {
super(textField);
caretPath.strokeProperty().unbind();
caretPath.fillProperty().unbind();
caretPath.setStrokeWidth(10);
caretPath.setStroke(Color.BLACK);
caretPath.setFill(Color.BLACK);
}
}
public static void main(String[] args) {
launch(args);
}
}

Maksym Rudenko
- 706
- 5
- 16
-
It works, it works but the cursor overlays the two close characters. It is possible to see them between two flashs. In fact the cursor width is only one-pixel. I can implement a space character. Do you have another idea ? – newBreach Dec 23 '17 at 07:52
-