[英]JavaFX: DialogPane won't display background Image
對話框窗格的 fxml 文件
<DialogPane xmlns:fx="http://javafx.com/fxml"
fx:controller="ToDoListMatt.ErrorDialogController" >
<content>
<GridPane fx:id="ErrorDialogPane" prefWidth="300" prefHeight="200" alignment="CENTER" hgap="10" vgap="10" >
<TextField fx:id="errorTextArea" prefHeight="10" prefWidth="150" style="-fx-background-color:red"/>
</GridPane>
</content>
</DialogPane>
我的 function DialogPane
會在哪里彈出
public static void showAlert(String errorType) {
try {
try {
Dialog<ButtonType> dialog = new Dialog<>();
dialog.initOwner(DialogController.dialogBG.getScene().getWindow());
dialog.setTitle("Ooopsie");
FXMLLoader fxmlLoader = new FXMLLoader();
dialog.getDialogPane().setContent(fxmlLoader.load());
dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);
dialog.show();
} catch (IOException e) {
e.printStackTrace();
}
}catch (NullPointerException e){
}
}
}
我的 css 代碼
#ErrorDialogPane{
-fx-background-image: url("Image2.gif");
}
基本上,由於自定義,我使用 DialogBox 作為Alert
的替代品。 我已經做過的事情:
.root
(主窗口)背景。initOwner
做了什么。 這會影響它嗎?我可以將程序發送給你們仔細檢查。 我正在創建一個 ToDoApp。
您需要將 css 文件鏈接到您的 fxml,例如:
<DialogPane xmlns:fx="http://javafx.com/fxml"
fx:controller="ToDoListMatt.ErrorDialogController"
stylesheets="@yourCssCode.css">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.