I have a TextField which has been given a TextFormatter, which has a filter that takes the input of the textfield, and ensures it is in a double format. It then uses a DoubleStringConverter to convert the filtered text into a double value. This is in a custom FXML component. See below for minimal example.
public SomeComponent implements Initializable {
@FXML
public TextField inputField;
public int min;
public void initialize(URL location, ResourceBundle resources) {
UnaryOperator<TextFormatter.Change> doubleFilter = change -> {
String newText = change.getControlNewText();
if (newText.matches("-?[0-9]{1,13}(\\.[0-9]*)?")) {
return change;
}
return null;
};
inputField.setTextFormatter(new TextFormatter<>(new DoubleStringConverter(), min, doubleFilter));
}
}
Another FXML component that uses this component ...
public SomeView implements Initializable {
@FXML
SomeComponent comp;
public void initialize(URL location, ResourceBundle resources) {
comp.inputField.getTextFormatter().valueProperty().bindBidirectional(SomeDataManagerClass.SomeSimpleDoubleProperty());
}
}
The bindBidirectional() is attempting to bind the TextField's converted value, to a SimpleDoubleProperty that exists elsewhere. But this returns the following error:
method Property.bindBidirectional(Property<CAP#1>) is not applicable
(argument mismatch; SimpleDoubleProperty cannot be converted to Property<CAP#1>)
Essentially I want to make use of the TextField's value (not the getText(), but the converted value) for binding to other properties.
I realise there is something wrong with the captured type inference with the TextFormatter, but I can't see anywhere in the JavaDocs that shows how to make use of the TextFormatter's double value. What is the point in using a DoubleStringConverter to convert the value if there isn't a simple way to extract that double from the TextField? I could use Double.parseDouble(inputField.getText()) but this seems pointless if I have already gone to the trouble of setting up a nice TextFormatter for the field.
How do I make use of the TextFormatter's valueProperty outside of SomeComponent?