I have main controller and an fxml file. In my main controller I have written:
@FXML
public static VBox spectrumListVBox;
And in my fxml file I have
<javafx.scene.layout.VBox fx:id="spectrumListVBox" prefHeight="324.0" prefWidth="191.0" />
In my main controller if I was trying to add multiple panes to this vbox and having errors. There are two things going on here. The first is that whilst running it would return a nullPointerException which at first I assumed was the pane I was adding to it was returning null. So I changed it to the following code. When I press a button I want it to add this new button to the vbox.
spectrumListVBox.getChrildren().add(new Button("Click Here");
However this too presented with a nullPointerException, which leads me to the conclusion that the VBox isn't being initialised by the FXML file. If I change the code in the main controller to:
public static VBox spectrumListVBox = new VBox();
This results in no warnings when compiled, however I do not actually see anything added to my vbox. I can confirm everything else is loading correctly (my controller and fxml has about 50 elements which are all hooked up and working correctly). I have closely checked that the fx:id and the controller element name are matching, and I have tried cleaning the project in case anything else was lingering on.