JavaFX FXML Controller initialize method not invoked

前端 未结 3 984
梦毁少年i
梦毁少年i 2021-01-18 04:33

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         


        
3条回答
  •  -上瘾入骨i
    2021-01-18 05:14

    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.

    1. 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.

    2. 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.

提交回复
热议问题