1

当我的程序在后台运行任务时,我试图显示一个加载弹出窗口。我正在为我的程序使用 Jfoenix 来赋予它材料设计的外观,并且我正在尝试使用 JFXDialog 来显示加载弹出窗口。我使用场景构建器在堆栈窗格中创建了一个弹出窗口...

<?xml version="1.0" encoding="UTF-8"?>

<?import com.jfoenix.controls.JFXSpinner?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>


<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="70.0" prefWidth="180.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <JFXSpinner>
         <padding>
            <Insets right="100.0" />
         </padding>
      </JFXSpinner>
      <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Loading">
         <StackPane.margin>
            <Insets left="50.0" />
         </StackPane.margin>
         <font>
            <Font name="Roboto Medium" size="20.0" />
         </font>
      </Text>
   </children>
</StackPane>

我正在尝试在 JFXDialog 中使用它...

private void createLoadingScreen() throws IOException{
    StackPane pane = FXMLLoader.load(getClass().getResource("LoadingScreen.fxml));
    StackPane stackPane = new StackPane();
    mLoad = new JFXDialog(stackPane, pane, JFXDialog.DialogTransition.CENTER);
}

我知道我没有完全正确地做到这一点,因为当我尝试在适当的时间提出它时它并没有出现。但是,我不知道我到底做错了什么。有人对此有任何指示吗?

4

1 回答 1

1

试试这个方法:

Parent parent = FXMLLoader.load(getClass().getResource("your fxml file.fxml"));
JFXDialogLayout dialogLayout = new JFXDialogLayout();
dialogLayout.setBody(parent);
JFXDialog dialog = new JFXDialog(stackpane, dialogLayout, JFXDialog.DialogTransition.BOTTOM);
dialog.show();

stackpane 是我的 StackPane 在 fxml 文件中的 id。您必须使用 JFXDialog 的堆栈窗格。它对我有用。

于 2019-01-19T19:25:05.987 回答