如何在JavaFX中在半透明背景上创建实心DropShadow效果
将其应用于具有半透明背景色的节点时,我产生了一种奇怪的如何在JavaFX中在半透明背景上创建实心DropShadow效果,javafx,javafx-8,Javafx,Javafx 8,将其应用于具有半透明背景色的节点时,我产生了一种奇怪的DropShadow效果,如下图所示: 上部节点具有纯色背景色,而另一个节点具有半透明背景色。两者的效果完全相同,但第二种效果显得过于模糊。我怎样才能纠正这个问题 编辑 这是一个有效的演示: public class App extends Application { public static void main(String[] args) { launch(args); } @Override public
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();
}
}
您使用什么代码应用阴影?@Vulcan效果。请包含示例代码,以便其他人可以轻松重现该问题。我刚刚成功地复制了它,但您可以通过向未来的观众提供示例代码来节省他们的时间。我想到的一个想法是将按钮放置在
堆栈窗格中,然后将阴影应用到该窗格中。到目前为止,我已经能够让阴影正常工作,但我无法正确管理大小。不过,我对JavaFX不太熟悉,也许您可以用这种方法解决它。如果您能够解决这个问题,请记住用解决方案回答您自己的问题,以供将来的观众使用:)