Skip to content

Instantly share code, notes, and snippets.

@prule
Last active June 21, 2019 04:41
Show Gist options
  • Save prule/5061089 to your computer and use it in GitHub Desktop.
Save prule/5061089 to your computer and use it in GitHub Desktop.
Griffon/JavaFX - Adding a change listener to a text field Part 1
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