I want to define my GUI entirely in FXML. I started with JavaFX templates that are shown everywhere from Oracle docs to Netbeans templates. In these templates there is no Stage defined in FXML, just the actual Scene with UI controlls in it. Something like:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fxskuska.FXMLDocumentController">
<children>
<Button layoutX="126" layoutY="90" text="Click Me!" onAction="#handleButtonAction" fx:id="button" />
<Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label" />
</children>
</AnchorPane>
That seemed okay, until the first thing I wanted to change - to set the window's name. That's when I realized Scene is not a Window (or a JFrame analogy), but Stage is.
When I tried to wrap all this inside a element, I couldn't set the fx:controller attribute to the AnchorPane, because it is not a root element anymore. I even tried to "outsource" it by using fx:include in the Stage file, but that just gave me an "Unexpected closing tag:scene" error.
- How to define Stage in FXML?
- Is Stage the JFX analogy of JFrame?
FXMLLoaderuses to create the controller.AnchorPanedoesn't have a controller property either. - James_D