JavaFX initialize() is not called on inner custom component
<p>I am using javaFX and I need to put custom components to my scene. Therefore I have "main_pane.fxml" with grid pane containing my components (for example DocumentModule). </p>

<h2>main_pane.fxml</h2>

<pre><code>&lt;GridPane  xmlns:fx="http://javafx.com/fxml" fx:controller="GUI.MainPane" gridLinesVisible="true" &gt; 
    &lt;padding&gt;
        &lt;Insets bottom="0" top="0" left="0" right="0" /&gt;
    &lt;/padding&gt;
     .
     .
     .
    &lt;DocumentModule fx:id="documentModule"
                minWidth="200" minHeight="400" 
                GridPane.columnIndex="0" GridPane.rowIndex="1"&gt;
    .
    .
    .   
    &lt;/DocumentModule&gt;
.
.
.
</code></pre>

<p></p>

<p>Each of them is defined in separate fxml file.</p>

<h2>document_module.fxml</h2>

<pre><code>&lt;GridPane  xmlns:fx="http://javafx.com/fxml"  fx:controller="GUI.DocumentModule" &gt;
    &lt;padding&gt;
        &lt;Insets bottom="0" top="0" left="0" right="0" /&gt;
    &lt;/padding&gt;
    &lt;ToolBar fx:id="toolBar" GridPane.rowIndex = "0" GridPane.columnIndex = "0" orientation="HORIZONTAL" &gt;
         .
         .
         .
    &lt;/ToolBar&gt;
    &lt;ScrollPane fx:id="scrollPane" hbarPolicy="AS_NEEDED" vbarPolicy="AS_NEEDED" GridPane.rowIndex = "1" GridPane.columnIndex = "0"&gt;
         &lt;DocumentView fx:id="documentView"/&gt;    
    &lt;/ScrollPane&gt;
&lt;/GridPane&gt;
</code></pre>

<p>Problem is that DocumentModule is not initialized after construction. It's constructor is called but not it's initialize(URL location, ResourceBundle resources) method. Therefore objects from fxml are not injected.</p>

<h2>Controller code for document module</h2>

<pre><code>public class DocumentModule extends GridPane implements Initializable {
      protected Document document;

@FXML
private DocumentView documentView;

@FXML
private ScrollPane scrollPane;
.
.
.
public DocumentModule() {
      System.out.println("Document Module constructed.");
      //this is called correctly

}
@Override
public void initialize(URL location, ResourceBundle resources) {
     System.out.println("Document Module initialized.");
     //This is not called at all.
}
</code></pre>

<p>}</p>

<p>For MainPane everything works fine but not for any of inner components.
The component tree seems to be constructed correctly, just the inner components are not initialized. Also the inner components are not dispalyed in application scene (if I load their fxml directly they work, if I use fx:include they are just displayed).</p>

<h2>MainPane controller</h2>

<pre><code>public final class MainPane extends GridPane implements Initializable {

    @FXML
    private DocumentModule documentModule;

    @FXML
    private EditModule editModule;


    public MainPane() {
        System.out.println("Main Pane constructed.");
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        System.out.println("Main Pane initialized.");
    }

}
</code></pre>

<h2>Application entry class' start method</h2>

<pre><code>@Override
public void start(Stage primaryStage) throws Exception {
     FXMLLoader fxmlLoader = new     FXMLLoader(getClass().getResource("main_pane.fxml"));
     GridPane root = fxmlLoader.load();
     Scene scene = new Scene(root, 800, 600);
     primaryStage.setMaximized(true);
     primaryStage.setMinWidth(800);
     primaryStage.setMinHeight(600);
     primaryStage.setTitle("App");
     primaryStage.setScene(scene);
     primaryStage.show();
} 
</code></pre>

<p>I haven't find any topic/page/blog with same problem. Few of them had similar symptoms, but no of solutins helped me. Does anyone have idea why initialize is not called on inner components?</p>

<p>Thanks!
Tom</p>