It takes three steps.
- Define controller Java class in your FXML file. Either in SceneBuilder or directly in XML.
- In controller define field VBox and annotate it with
@FXML
and its name use in XML like fx:id
. This will tell to JavaFX to bind your field with correct instance of VBox.
- Do whatever you want with VBox
XML definition (notice fx:controller
and fx:id
):
<BorderPane prefHeight="600.0" prefWidth="1024.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="foo.bar.MainController">
<center>
<VBox fx:id="content" fillWidth="true" prefHeight="200.0" prefWidth="100.0" />
...
Controller class:
public class MainController {
@FXML
private VBox content;
}
If you want to call controller class from outside, you will get instance of controller from right instance of FXMLLoader
like this:
MainController controller = (MainController) loader.getController();