Javafx ComboBox set T插入符号位置



当我在可编辑的组合框中按下一个键时,插入符号始终位于位置 0,而不是预期的位置 1。无论我键入什么文本,插入符号位置都应在输入到可编辑组合框中的最后一个字符之后。取而代之的是,插入符号位置始终位于位置 0。知道如何在输入文本后正确定位插入符号吗?

在java Swing中,我曾经实现过如下目标

((JTextField)jComboBox.getEditor().getEditorComponent()).setCaretPosition(enteredString.length());

但是来自JavaFX的ComboBox编辑器没有方法getEditorComponent((。 甚至来自JavaFX的TextField也没有方法getCaretPosition((;

知道如何在可编辑组合框中输入文本后正确定位插入符号吗?

//To get the position
int origCarrotPos = comboBox.getEditor().getCaretPosition();
//To set the position
int carrotPos = 5;
comboBoxgetEditor().positionCaret(carrotPos);

最新更新