Re: Problem with JavaFX ChangeListener?
On 12/11/2014 15:36, Arne Vajh??j wrote:
On 12/11/2014 6:08 PM, Knute Johnson wrote:
I'm trying to teach myself JavaFX and have hit a snag. In the program
below I add a ChangeListener to a TextField. The Java8 method works
fine, adding an anonymous ChangeListener class works fine but I can't
create a class that implements ChangeListener and get it to compile.
class LengthListener<String> implements ChangeListener<String> {
^^^^^^^^ remove this (it has a very bad
impact when String is used later!)
private final int length;
public LengthListener(int length) {
this.length = length;
}
@Override public void changed(
ObservableValue<? extends String> observable,
String oldValue,String newValue) {
if (newValue.length() > length)
((StringProperty)observable).setValue(
newValue.substring(0,length));
}
}
textField.textProperty().addListener(new LengthListener(4));
Arne
Thanks Arne, that was why it wouldn't compile!
--
Knute Johnson