将其应用于具有半透明背景颜色的节点时,我有一种奇怪的DropShadow
效果,如这张图所示:
上层节点的背景色为纯色,而另一个节点为半透明的背景色。两者具有相同的精确效果,但第二个效果太模糊。我该如何纠正?
这是一个工作示例:
public class App extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
// The drop shadow effect.
DropShadow effect = new DropShadow();
effect.setBlurType(BlurType.GAUSSIAN);
effect.setColor(Color.rgb(0,0,0, .5));
effect.setSpread(0);
effect.setOffsetX(0);
effect.setOffsetY(7);
// Node with solid background color.
Button button1 = new Button("BUTTON");
VBox.setMargin(button1, new Insets(0, 0, 15, 0));
button1.setStyle("-fx-background-color: rgb(238,238,238);");
button1.setEffect(effect);
// Node with translucent background color.
Button button2 = new Button("BUTTON");
VBox.setMargin(button2, new Insets(15, 0, 0, 0));
button2.setStyle("-fx-background-color: rgba(238,238,238, .5);");
button2.setEffect(effect);
VBox root = new VBox(button1, button2);
root.setStyle("-fx-background-color: white;");
root.setAlignment(Pos.CENTER);
root.setPadding(new Insets(15));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}