我试图将dropshadow添加到我的警报框中,我将其样式设置为透明,并将initOwner设置为当前阶段。按钮上的阴影有效,但警报框上没有。为什么.alertBox中的dropShadow不起作用?我应该将阴影放置在其他位置吗?这就是我创建警报的方式:
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initOwner(stage);
alert.initStyle(StageStyle.TRANSPARENT);
DialogPane dialog = alert.getDialogPane();
dialog.setGraphic(null);
dialog.getStyleClass().add("alertBox");
这是我的CSS:
.alertBox{
-fx-background-color: #2A2E37;
-fx-border-color: #363b41;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,1.6) , 5, 0.0 , 0 , 2 );
}
.alertBox > *.button-bar > *.container{
-fx-background-color: transparent;
-fx-pref-height: 50
}
.alertBox:header *.header-panel{
-fx-background-color: transparent;
}
.alertBox:header *.header-panel *.label{
-fx-font-size: 14px;
-fx-font-weight: bold;
-fx-pref-height: 25;
-fx-text-fill: #363b41;
-fx-alignment: center;
-fx-background-color: transparent;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0) , 0, 0.0 , 0 , 0 );
}
.alertBox > *.label.content{
-fx-font-size: 12px;
-fx-text-fill: #bcbcbc;
-fx-alignment: center;
-fx-pref-height: 50;
-fx-padding: 0,0,10,0;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,1.6) , 5, 0.0 , 0 , 2 );
-fx-background-color: transparent;
}
.alertBox Button{
-fx-text-fill: #bcbcbc;
-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,1.6) , 5, 0.0 , 0 , 0);
-fx-background-color: #2A2E37;
}
编辑:
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
Pane root = new FXMLLoader(LoggedFirstStyle.class.getResource("/FXML/logged-first.fxml")).load();
Scene scene = new Scene(root);
scene.getStylesheets().add(LoggedFirstStyle.class.getResource("/css/logged-first.css").toString());
scene.setFill(Color.TRANSPARENT);
stage = new Stage();
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
stage.setWidth(primaryScreenBounds.getWidth());
stage.setHeight(primaryScreenBounds.getHeight());
stage.setX(primaryScreenBounds.getMinX());
stage.setY(primaryScreenBounds.getMinY());
答案 0 :(得分:0)
这是一个非常简单但带有DropShadow的警报框的可行示例,希望对您有所帮助!
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Drop Shadow!");
primaryStage.initStyle(StageStyle.DECORATED);
StackPane root = new StackPane();
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initStyle(StageStyle.TRANSPARENT);
DialogPane dialog = alert.getDialogPane();
dialog.setGraphic(null);
dialog.setStyle(
"-fx-background-color: #2A2E37; -fx-border-color: #363b41; -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,1.6) , 5, 0.0 , 0 , 2 );"
);
root.getChildren().addAll(dialog);
root.setStyle(
"-fx-background-color: #ffffff;"
);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
我无法使用CSS,我不知道为什么,也没有太多时间来调查根本原因:)