我刚刚开始将JavaFx用于新的应用程序.
我知道如何在java代码中设置窗口标题,但如何在fxml文件中设置它?
谢谢你的帮助.
编辑:这是我的代码
@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();
}
Run Code Online (Sandbox Code Playgroud)
我只想在Main.fxml中设置标题.
Seb*_*ian 10
要在FXML中设置舞台的标题,您需要在FXML中构建舞台,如下所示:
<?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>
Run Code Online (Sandbox Code Playgroud)
如果你只是通过FXML构建场景的根元素(在我的例子中,VBox)然后像你那样把它放到一个场景中(这是常见的方式),那么就不可能在FXML中设置标题直接(没有代码).