[英]Why can't I see the changes in my project but I see them in the fxml file?
我在 JavaFX 中的項目有問題。 我使用 SceneBuilder 將所有更改保存到 fxml 文件,但是當我運行項目時,我只看到空的背景,甚至工作區的大小也沒有改變。 我嘗試清理項目和工作區,但問題是一樣的。 我有刷新項目和所有文件,什么都沒有,我選擇“使用本機掛鈎或池刷新”,但我一直遇到同樣的問題。 有沒有人有其他想法? 我使用 java 13 和 JavaFX 11
主窗口文件
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.Pane?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com /fxml/1" fx:controller="application.MainWindowController">
<children>
<Label fx:id="labelText" layoutX="286.0" layoutY="42.0" prefHeight="17.0" prefWidth="0.0" text="" />
<Button fx:id="button1" layoutX="270.0" layoutY="82.0" mnemonicParsing="false" text="OK" />
</children>
</Pane>
主類
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = new BorderPane();
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass()
.getResource("mainWindow.fxml").toExternalForm());
primaryStage.setTitle("Test");
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
MainWindowController 類
package application;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class MainWindowController implements Initializable {
@FXML
Label labelText;
@FXML
Button button1;
@Override
public void initialize(URL location, ResourceBundle resources) {
labelText.setText("Start");
}
}
我認為問題出在您的主要啟動方法中。 試試這個實現。
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("mainWindow.fxml"));
primaryStage.setTitle("Test");
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.