加載GUI此函數加載我的「請稍候...」鬼:我怎樣才能顯示JavaFX的
public void showLoading(Stage ownerStage){
try {
FXMLLoader loader = new FXMLLoader();loader.setLocation(MainApp.class.getResource("/de/ern/loading/Loading.fxml"));
AnchorPane page = (AnchorPane) loader.load();
LoadingController controller = loader.getController();
controller.setLoadingText("Please wait...");
waitStage = new Stage();
waitStage.setTitle("Please wait");
waitStage.getIcons().add(new Image(getClass().getResourceAsStream("logo.png")));//setzt das Icon
waitStage.initModality(Modality.WINDOW_MODAL);
waitStage.initOwner(ownerStage);
Scene scene = new Scene(page);
waitStage.setScene(scene);
waitStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
我怎麼有稱呼它,因爲當我直接調用它,它總是空的。只顯示標題窗格。我發現了很多Swing的代碼片段,但不是javafx。
編輯:
我把它從主界面的這樣的控制器:
mainApp.showLoading(primaryStage);
AllgemeinTab liveWerte = new AllgemeinTab(this);
liveWerte.setName(getAllgTabName());
liveWerte.setBeschreibungDe(getAllgTabBeschreibungDe());
,並在這之後,緊跟着一個大型數據庫交易。
這是我FXML文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="64.0" prefWidth="292.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.ernst.loading.LoadingController">
<children>
<ImageView fx:id="imgLoading" fitHeight="25.0" fitWidth="25.0" layoutX="20.0" layoutY="20.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="19.0" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="20.0">
<image>
<Image url="@loading.gif" />
</image>
</ImageView>
<Text layoutX="54.0" layoutY="25.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Status:" AnchorPane.topAnchor="17.0">
<font>
<Font name="System Bold" size="12.0" />
</font></Text>
<Text fx:id="txtLoadingDescription" layoutX="54.0" layoutY="24.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Beschreibung..." wrappingWidth="230.44140625" AnchorPane.topAnchor="30.0" />
</children>
</AnchorPane>
創建併發布[MCVE]。您發佈的代碼似乎沒有任何問題。 –
你可以粘貼你的fxml文件嗎? – ttarczynski