I'm just starting to use JavaFx for a new application.
I know how to set the window title in the java code but how to set it in a fxml file ?
Thanks for your help.
Edit : Here is the code I have
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
primaryStage.setTitle(applicationName);
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
I just want set the title in Main.fxml.
to set the title of the stage in FXML, you need to construct the stage in FXML, like this:
<?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 construct the root element of the scene (in my example, the VBox) via FXML and then put it into a scene afterwards like you do it (which is the common way), then it is impossible to set the title in FXML directly (without code behind).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With