Css JavaFx:自定义警报对话框
我想在警报对话框中自定义按钮、按钮容器、背景颜色和AlertType图标 尝试以下两种解决方案: 我想我提到的CSS代码应该适用于所有警报对话框窗格? 不知道我在这里错过了什么Css JavaFx:自定义警报对话框,css,javafx,dialog,Css,Javafx,Dialog,我想在警报对话框中自定义按钮、按钮容器、背景颜色和AlertType图标 尝试以下两种解决方案: 我想我提到的CSS代码应该适用于所有警报对话框窗格? 不知道我在这里错过了什么 private static void createSimpleInformationDialog(String message){ Alert alert = createSimpleInformationAlert(message, AlertType.INFORMATION); alert.ge
private static void createSimpleInformationDialog(String message){
Alert alert = createSimpleInformationAlert(message, AlertType.INFORMATION);
alert.getDialogPane().setHeaderText(StringTools.isNull(null, ""));
alert.getDialogPane().setMaxWidth(200);
alert.getDialogPane().setMinWidth(150);
alert.getDialogPane().setPadding(new Insets(0, 10, 0, 10));
alert.showAndWait();
}
private static Alert createSimpleInformationAlert(String message, AlertType type) {
Alert alert = new Alert(type);
alert.setTitle(Lang.get(Defs.FX_DIALOGS_EXCEPTIONS_GENERIC_TITLE));
alert.setContentText(message);
alert.initModality(Modality.APPLICATION_MODAL);
alert.initOwner(FXMain.getInstance().getStage());
return alert;
}
CSS文件:
.dialog-pane{
-fx-border-color:black;
-fx-border-width:2.0px;
}
/**Costumization of The Bar where the buttons are located**/
.dialog-pane > .button-bar > .container {
-fx-background-color:black;
}
.dialog-pane > .content.label {
-fx-padding: 0.5em 0.5em 0.5em 0.5em;
-fx-background-color: yellow;
-fx-text-fill:black;
-fx-font-size:15.0px;
}
/**Costumization of DialogPane Header**/
.dialog-pane:header .header-panel {
-fx-background-color: black;
}
.dialog-pane:header .header-panel .label{
-fx-background-color: yellow;
-fx-background-radius:10px;
-fx-text-fill:black;
-fx-font-size:15.0px;
}
/**Costumization of Buttons**/
.dialog-pane .button{
-fx-background-color:black;
-fx-text-fill:white;
-fx-wrap-text: true;
-fx-effect: dropshadow( three-pass-box, yellow, 10.0, 0.0, 0.0, 0.0);
-fx-cursor:hand;
}
.dialog-pane .button:hover{
-fx-background-color:white;
-fx-text-fill:black;
-fx-font-weight:bold;
}
也许你的CSS文件中的CSS选择器是错误的(我不知道我没有试过)。如果是这样,如果您使用,您可能会得到一些帮助,以确定要使用的正确选择器。另一个地方是查看JavaFX源代码库中的
moderna.css
文件。Moderna可能会显示默认对话框的样式。但是,如果默认对话框没有自定义按钮的样式(它们可能没有),那么在moderna.css中可能不会有特定的样式规则。我认为还有一个内置的可以帮助您(虽然我还没有使用它的最新版本,所以我不确定是否仍然支持SceneBuilder中的css分析器)。