0

I'm beginner in JavaFX. For each view in FXML, I have to define 1 controller. But it doesn't work if I define controller for main view and set up 2 sub-view. Is there anyway to use 1 controller for 2 or more view in JavaFX?

Einsamer
  • 1,069
  • 4
  • 17
  • 34
  • 1
    Yes, you can do this. No, you should not do this. – jewelsea Dec 17 '15 at 02:39
  • Can you explain why we should not do it? – Einsamer Dec 17 '15 at 02:41
  • Because it is confusing and a source of bugs. Generally, things are injected into controllers using @FXML, if you share a controller, each time you load a new FXML document you will likely wildly corrupt the existing data in the controller with newly injected data from the loader. You want to share domain model classes (not view model or presentation classes like controllers). – jewelsea Dec 17 '15 at 02:44

0 Answers0