I use selectionAll () to select all the text in my text box, but it just works when the focus comes from the keyboard (e.g. Tab).
If I clicked in the text box, it selects the text only for a very short period of time. But it should work like with the focus that comes from the keyboard.
flaschenPreis.focusedProperty().addListener(new ChangeListener<Boolean>() { public void changed(ObservableValue ov, Boolean t, Boolean t1) { if ( flaschenPreis.isFocused() && !flaschenPreis.getText().isEmpty()) { flaschenPreis.selectAll(); } } }); literPreis.focusedProperty().addListener(new ChangeListener() { public void changed(ObservableValue ov, Object t, Object t1) { if (literPreis.isFocused() && !literPreis.getText().isEmpty()) { literPreis.selectAll(); } } });
flaschenPreis und literPreis - my text fields
Sonja source share