Hey everyone,
I would like to set the caret of a TextField to the end of the text when the TextField loses the focus, so that the last part of the file name will be shwon and not the first part. I´ve tried the following:
ChangeListener<Boolean> onLooseFocus = new ChangeListener<Boolean>()
{
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue)
{
if (!newValue.booleanValue())
{
textFieldDateiname.end();
System.out.println(textFieldDateiname.getCaretPosition());
// At this point the caret is at the end and it will show:
//ReadOnlyIntegerProperty [bean: TextField[id=textFieldDateiname, styleClass=text-input text-field], name: caretPosition, value: 76]
}
}
};
this ChangeListener is added to the focusedProperty() method of my TextField
textFieldDateiname.focusedProperty().addListener(onLooseFocus);
It doesn´t work, although the caret is temporarily on the end of the text field.
Another question: If it works, I would like to reuse the ChangeListener onLooseFocus for diefferent TextField. So I would like to know which TextField lost the focus. I tried
observable.getSoruce(); // like it works with keyEvent
System.out.println(observable); // -> ReadOnlyBooleanProperty [bean: TextField[id=textFieldDateiname, styleClass=text-input text-field], name: focused, value: false]
So the id of the source of the ChangeEvent is known...
Any ideas?
Thanks,
Lukas
Edited by: 972241 on 20.11.2012 06:08