JavaFx FXML load file issues with setting root
<fx:root>
specifies a "dynamic root" for your FXML file; this means the root of the FXML file is an object that is set on the loader prior to loading the file. This is typically used for custom controls, where you want the control to be a subclass of Node
that can be instantiated using regular Java code, but want to define its layout using FXML. Proper use of <fx:root>
(or at least an example of how it can be used) is shown in the standard documentation. In particular, if you use <fx:root>
you must:
- Create an
FXMLLoader
instance, instead of using the static convenienceFXMLLoader.load(URL)
method - Call setRoot(...) on that instance, and pass in the object that is to be the root of the FXML.
For standard FXML use, you just use a regular instance declaration as the root. Almost every example available works this way: probably the best place to start is the official tutorial. In your case, since you want a VBox
, you probably just need
<VBox xmlns="javafx.com/javafx/8"; xmlns:fx="javafx.com/fxml/1"; fx:controller="divergex.DivergexGUIController">
<!-- ... -->
</VBox>
Edit If Netbeans is giving you issues, I recommend using Eclipse with the e(fx)clipse plugin. There's a very barebones, but pretty much all you need, tutorial.
uncheck id::root in scence builder or change id::root to vbox