I tried to implement the mvc model with a .fxml view made in JavaFX Scene Builder, but there was a problem with the view alert, after which it would update the data. It is necessary to trigger the method from the model, which not only updates the state of some elements of the view, but also creates new ones or deletes existing ones. Found the following options for changing the parameters of existing elements of the view:

  1. Re-creating the scene:

    public class View extends Application { private static Stage stage; @Override public void start(Stage curStage) throws Exception{ stage = curStage; stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("FirstView.fxml")), stage.getWidth(), stage.getHeight())); stage.show(); } public static void begin() { launch(); } public void update() throws IOException { stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("FirstView.fxml")), current.getScene().getWidth(), current.getScene().getHeight())); } 

    And then change the view in the initialize(URL url, ResourceBundle rb) method initialize(URL url, ResourceBundle rb) controller.

  2. AnimationTimer - relevant mainly for the frequent change of parameters of elements of the presentation

  3. Binding Found in the Internet such an example:

      label.textProperty().bind(textField.textProperty()); 

    Made by analogy:

      label.textProperty().bind(Model.getIntance().getFirstUser().nickProperty()); 

    nickProperty() - similarly returns StringProperty .

    But for some reason this example did not work for me:

      textField.textProperty().bind(Model.getIntance().getFirstUser().nickProperty()); 

I also met some horror on this topic on the Internet, where bind commands were laid in the .fx files in the visual presentation constructors, linking the presentation elements with Java variables (including in a two-way manner), but frankly it is not enough that understood because I do not have any .fx files, only .fxml, and even if I create .fx, the development environment will assume that this is just a text file ...

Help me figure it all out. Are these ways to update the JavaFX representation? How will the presentation be properly updated? How can I do to add / delete objects when updating the view?

  • @ Andrey759; To format a code, select it with the mouse and click on the {} button of the editor. - Deleted
  • About textField.textProperty (). Bind (Model.getIntance (). GetFirstUser (). NickProperty ()); It was possible to find out that at least the bidirectional binding works in the case of a text field =) - Andrey759

0