【发布时间】:2014-12-04 10:23:34
【问题描述】:
如果您将 JavaFX 文本字段设置为只读模式,则它们不会显示文本插入符号。这是一个例子:
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);
}
}
虽然仍然可以使用 Shift+光标键选择文本,但不会显示插入符号。有人知道解决方法吗?
【问题讨论】:
-
为什么在
ReadOnly文本控件上需要TextCaret?当鼠标指针悬停在文本上时,您想设置鼠标指针的样式吗? -
我不想改变鼠标指针。我希望 textarea 显示 TextInputControl.getCaretPosition() 的位置。我猜 TextArea 没有显示插入符号的原因是你不需要它,因为当它是只读的时你无论如何都不能插入任何文本。但这是错误的(IMO),因为您仍然可以使用光标键选择文本,为此您绝对需要插入符号。
-
也许允许编辑和覆盖编辑事件以模拟只读!?