MyModel.java :
public class MyModel { private StringProperty myString = new SimpleStringProperty(); public void setMyString(String myString) { this.myString.set(myString); } public String getMyString() { return myString.get(); } public StringProperty getMyStringProperty() { return myString; } }
Then create an instance of MyModel as a singleton bean (it looks like you are using Spring). And enter your model where you need it:
@Bean public MyModel myModel() { return new MyModel(); }
Then enter it and bind to the property:
public class MyPresenter { @FXML TextField myTextField; @Autowired MyModel myModel; public void initialize() { myTextField.textProperty().bind(myModel.getMyStringProperty()); } }
If someone is now updating the myString property, the UI myTextField will also be updated.
You can also register some custom handler for these properties or use twoWayBinding.
Thus, you do not need to use it as a user interface element, but it can also use it as a kind of data pipeline.
source share