I'm using a TextField
to display the path of a directory the user has opened in my application.
Currently, if the path can't fit inside the TextField
, upon focusing away/clicking away from this control, it looks like as if the path has become truncated:
I want the behaviour of TextField
set such that when I focus away from it, the path shown inside automatically scrolls to the right and the user is able to see the directory they've opened. I.e. something like this:
How can I achieve this? I've tried adapting the answer given from here
as follows in initialize()
method in my FXML Controller
class:
// Controller class fields
@FXML TextField txtMoisParentDirectory;
private String moisParentDirectory;
// ...
txtMoisParentDirectory.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldStr, String newStr) {
moisParentDirectory = newStr;
txtMoisParentDirectory.selectPositionCaret(moisParentDirectory.length());
txtMoisParentDirectory.deselect();
}
});
However it doesn't work.