When using a readonly textarea (also applies to textfields), no text caret is displayed. Example:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
public class TextAreaReadOnly extends Application {
public TextAreaReadOnly() {
}
@Override
public void start(Stage primaryStage) throws Exception {
TextArea textarea = new TextArea();
textarea.setText("This is all\nreadonly text\nin here.");
textarea.setEditable(false);
Scene scene = new Scene(textarea, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This is not a good default behaviour in my opinion, since one can still select text in a readonly field with Shift+Cursor Keys (e.g. to copy selected text). But to do so requires to display a caret.
It happens in TextInputControlSkin, where
caretVisible = new BooleanBinding() {
{ bind(textInput.focusedProperty(), textInput.anchorProperty(), textInput.caretPositionProperty(),
textInput.disabledProperty(), textInput.editableProperty(), displayCaret, blink);}
@Override protected boolean computeValue() {
// RT-10682: On Windows, we show the caret during selection, but on others we hide it
return !blink.get() && displayCaret.get() && textInput.isFocused() &&
(isWindows() || (textInput.getCaretPosition() == textInput.getAnchor())) &&
!textInput.isDisabled() &&
textInput.isEditable();
}
};
=> textInput.isEditable() should either be removed completely or there should be an option to display the caret even if textInput.isEditable() == false
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
public class TextAreaReadOnly extends Application {
public TextAreaReadOnly() {
}
@Override
public void start(Stage primaryStage) throws Exception {
TextArea textarea = new TextArea();
textarea.setText("This is all\nreadonly text\nin here.");
textarea.setEditable(false);
Scene scene = new Scene(textarea, 600, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
This is not a good default behaviour in my opinion, since one can still select text in a readonly field with Shift+Cursor Keys (e.g. to copy selected text). But to do so requires to display a caret.
It happens in TextInputControlSkin, where
caretVisible = new BooleanBinding() {
{ bind(textInput.focusedProperty(), textInput.anchorProperty(), textInput.caretPositionProperty(),
textInput.disabledProperty(), textInput.editableProperty(), displayCaret, blink);}
@Override protected boolean computeValue() {
// RT-10682: On Windows, we show the caret during selection, but on others we hide it
return !blink.get() && displayCaret.get() && textInput.isFocused() &&
(isWindows() || (textInput.getCaretPosition() == textInput.getAnchor())) &&
!textInput.isDisabled() &&
textInput.isEditable();
}
};
=> textInput.isEditable() should either be removed completely or there should be an option to display the caret even if textInput.isEditable() == false