I am trying to fill ListView from the content of a simple ArrayList. Here is my
Controller.java file:
package design;
import java.net.URL;
import jav
I needed to implement Initializable to the class and add an @Override before calling the method.
If I see correctly, you actually don't use the URL and the ResourceBundle parameters in you initialize()
method.
If the URL is the path to your fxml file, and the ResourceBundle contains internatonalization properties for your GUI, then you should define your initialize()
method without parameters, but annotated with @FXML
. The URL and the ResourceBundle should be passed to the FXMLLoader.
Like
FXMLLoader loader = new FXMLLoader(URL, rb);
and
@FXML
private void initialize() { ... }
This way initialize()
will be automatically invoked.
The issue was that the Controller's wasn't being initialized as the asker of the question expected.
The operation of the FXMLLoader in Java 8 is a little weird.
If you define a no-parameter initialize()
method in your Controller and don't implement the Initializable interface, then the FXML loader will still automatically invoke the initialize method.
If instead, you define a parameterized public void initialize(URL url, ResourceBundle rb)
method in your Controller, then the FXML loader will not automatically invoke the initialize method unless your controller also implements the Initializable interface.
As the code in the question was using a parameterized initialize method and not also implementing Initializable, the initialization was not occurring.