Basically, i need to retrieve a VBox from an fxml file and i'm using scene.lookup. But if i search for it, it just crashes with a NullPointerException.
So i tried to print what scene.lookup() finds, and it just finds null (duh), but i can't understand why.
This is my Main class:
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception{
FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, 600, 575);
Controller controller = new Controller();
controller.setScene(scene);
System.out.println(scene.lookup("#vBox"));
stage.setScene(scene);
stage.setTitle("Test");
stage.setResizable(false);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
And this is my fxml file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="575.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<top>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<Button fx:id="addBtn" mnemonicParsing="false" onAction="#addEventHandler" prefHeight="30.0" prefWidth="75.0" text="Add" />
<Button fx:id="editBtn" mnemonicParsing="false" prefHeight="30.0" prefWidth="75.0" text="Edit..." />
<Button fx:id="delBtn" mnemonicParsing="false" prefHeight="30.0" prefWidth="75.0" text="Delete" />
</items>
</ToolBar>
</top>
<center>
<ScrollPane fx:id="scrollPane" prefHeight="515.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<content>
<VBox fx:id="vBox" fillWidth="true" />
</content>
</ScrollPane>
</center>
</BorderPane>