To set the scene title in FXML, you need to create a stage in FXML, for example:
<?xml version="1.0" encoding="utf-8"?> <?import javafx.scene.layout.VBox?> <?import javafx.stage.Stage?> <?import javafx.scene.Scene?> <?import javafx.scene.control.Label?> <Stage title="Some Stage"> <scene> <Scene> <VBox xmlns:fx="http://javafx.com/fxml"> <children> <Label text="John Doe"/> </children> </VBox> </Scene> </scene> </Stage>
If you only create the root element of the scene (in my example, VBox) via FXML, and then put it in the scene later, as you do (which is the usual way), then it is impossible to set the title in FXML directly (without the code behind).
source share