0

Here's my situation. I have a javafx pane which I don't want to recreate each time I show it, because I want to keep all filled by user fields in between switching between views.

For that purpose I did this:

@FXML
private void initialize() {
    createOrderPane = FxmlUtils.fxmlLoader(CREATE_ORDER_FXML);
}

public void setCenter(String fxmlPath) {
    if(CREATE_ORDER_FXML.equals(fxmlPath)) {
        borderPane.setCenter(createOrderPane);
    }
    else {
        borderPane.setCenter(FxmlUtils.fxmlLoader(fxmlPath));
    }
}

so in case user wants to see CREATE_ORDER_FXML it doesn't reload it, but uses already existing instance.

The problem is that some parts of the view should be reinitalized. For example database might change and I want to refresh some comboboxes which reads value from DB. How to achieve that?

Is there some onShow property? Or maybe I am able to get to the controller of createOrderPane object?

Mateusz Gaweł
  • 673
  • 1
  • 8
  • 22
  • Have you learned the [MVC](https://stackoverflow.com/questions/32342864/applying-mvc-with-javafx) pattern? – SedJ601 Mar 27 '19 at 20:55
  • lol, yes. What is this question? :) – Mateusz Gaweł Mar 27 '19 at 21:04
  • 1
    I am guessing that if you applied an MVC pattern, you would not have this problem? – SedJ601 Mar 27 '19 at 21:39
  • Possible duplicate of [Passing Parameters JavaFX FXML](https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml) – Slaw Mar 27 '19 at 22:05
  • 1
    With access to the controller, you can (re)initialize the view from within whatever method is called to show it. Another option is to cause the model to update and have the "create order" view observe and react to those changes. And there are `onShown` properties for `Window` and `Dialog`, but for other situations you'll need to implement it yourself. In your view, you could always listen to the root's `parent` property—assuming it gets removed from the `borderPane` when you show a different view. – Slaw Mar 27 '19 at 22:11

0 Answers0