0

In my Java FX application I have an FXML file with a TableView. There's a button that opens another FXML file with a formular to add entries to the table.

Each FXML file has its own controller class, so I can't access the TableView in the controller for the second FXML. How to call the initialize()-method (which updates the table) from the "new entry" form?

Or do I have to use the same controller class for both fxml files?

I've done quite a lot of research, but I could only find ways to update the table in the controller that contains the TableView.

MrSteed
  • 13
  • 1
  • 6
  • Using the same controller class for both FXML files won't help at all: you still have the same problem (each time you load the FXML you get a new instance of the specified class, so you would still need access to the new instance). You can get a reference to the controller from the `FXMLLoader` after you load the FXML. See https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml/14190310#14190310 – James_D May 31 '17 at 11:58
  • Also, the `initialize()` method is called automatically after loading the FXML: you should never need to call this. But you would need the techniques in the post linked above to call other methods. – James_D May 31 '17 at 12:07
  • A very simple way is to pass the reference of one controller to other and vice versa using one method :) . So you can call methods from the other controller and/or use `gettter methods` to access any element you want . !Warning! You can use a `FXML` Controller reference after it has been successfully initialized . That happens when the `initialize()` method has been called . – GOXR3PLUS May 31 '17 at 13:18

0 Answers0