Last active
June 21, 2019 04:41
-
-
Save prule/5061089 to your computer and use it in GitHub Desktop.
Griffon/JavaFX - Adding a change listener to a text field Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.beans.value.ChangeListener | |
import javafx.beans.value.ObservableValue | |
import org.apache.commons.lang.StringUtils | |
// model | |
@FXBindable String amount1 | |
// view | |
textField(id: 'amount1', text: bind(model.amount1Property)) | |
noparent { | |
amount1.textProperty().addListener(new ChangeListener<String>() { | |
@Override | |
public void changed(ObservableValue<? extends String> observable, | |
String oldValue, String newValue) { | |
try { | |
if (StringUtils.isNotBlank(newValue)) { | |
Integer.parseInt(newValue); | |
} | |
} catch (Exception e) { | |
observable.setValue(oldValue); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment