如何在javafx中显示加载gui

时间:2015-10-28 14:40:06

标签: user-interface javafx

此功能加载我的“请稍候......”gui:

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();
    }
}

我如何调用它,因为当我直接调用它时,它总是空的。仅显示带标题的窗格。我找到了很多代码片段,但是没有针对javafx。

编辑:

我从主gui的控制器中这样称呼它:

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>

2 个答案:

答案 0 :(得分:0)

您可以显示&#34;加载GUI&#39;通过显示ProgressIndicator

因此,请显示ProgressIndicator,然后您需要在新线程中执行Backgroundwork,然后使用新内容替换ProgressIndicator。

helper.compareArray

答案 1 :(得分:0)

您可能需要查看PreloaderOracle Doc)。 Preloader是一个非常小的应用程序,在应用程序加载之前会加载一个Stage,您可以向预加载器发送一些信息以显示进度。

这可能会为您提供更多选择

相关问题