In JavaFX 2, I created a custom TableCell that overrides the startEdit () method to request focus. Therefore, as soon as I call the edit command in the cell, the edit text box that appears appears.
The next step is to set the caret position to the end of the text field. But for unknown reasons, this does not work. It is always placed before the 1st char.
Here is what I have tried so far:
public void startEdit() { if (!isEmpty()) { super.startEdit(); createTextField(); setText(null); textField.end(); setGraphic(textField); ((TextField)getGraphic()).end(); textField.end(); Platform.runLater( new Runnable() { @Override public void run() { getGraphic().requestFocus(); } }); } } public void startEdit() { if (!isEmpty()) { super.startEdit(); createTextField(); setText(null); setGraphic(textField); textField.end(); Platform.runLater( new Runnable() { @Override public void run() { getGraphic().requestFocus(); textField.end(); ((TextField)getGraphic()).end(); } }); } } public void startEdit() { if (!isEmpty()) { super.startEdit(); createTextField(); setText(null); textField.end(); setGraphic(textField); ((TextField)getGraphic()).end(); getGraphic().requestFocus(); ((TextField)getGraphic()).end(); textField.end(); } }
The logical approach would be to request focus on the text box and then move the caret, but it doesn't seem to work for any reason.
Can someone enlighten me?
source share