我正在尝试让我的Pane在视觉上更好,所以我做的是:设置我的舞台为UNDECORATED(可以),尝试添加drop-shadow效果(不行)。我找到了一些类似的案例,但都无法正常工作:creating undecorated stage in javafx 2.0和How to add shadow to window in JavaFX?。看起来drop-shadow并没有被设置。我不明白为什么会这样。以下是我的代码:
public static int showConfirmDialog(Window father, String title, String body, String[] msgBtn)
{
System.out.println("La vai eu");
AnchorPane ap = createPaneWithButton(2, msgBtn,body);
ap.setEffect(initDropShadow());
Scene scene = new Scene(ap);
Stage stage = new Stage();
stage.setTitle(title);
scene.setFill(null);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
return 1;
}
private static AnchorPane createPaneWithButton(int qtBtn, String[] msgsBtn, String body) {
AnchorPane ap = createPane();
HBox laneBtn = new HBox(30);
VBox vbox = new VBox(20);
BorderPane layout = new BorderPane();
Button btn;
for(int i = 0; i < qtBtn; i++ ){
btn = new Button();
btn.setText(msgsBtn[i]);
laneBtn.getChildren().add(btn);
}
vbox.getChildren().add(new Text(body));
vbox.getChildren().add(laneBtn);
layout.setCenter(vbox);
ap.getChildren().add(layout);
return ap;
}
private static AnchorPane createPane() {
AnchorPane ap = new AnchorPane();
ap.setLayoutX(250);
ap.setLayoutY(50);
return ap;
}