Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i add shadow for undecorated stage with JavaFX? [duplicate]

What i see:

enter image description here

What i want to see:

enter image description here

I tried to add shadow with css but effect was visible only in SceneBuilder. Program window was shown without shadow.

.rootBorder {
    -fx-effect: dropshadow(gaussian, rgba(0, 0, 0, 0.4), 10, 0.5, 0.0, 0.0);
}

How can i add some shadow to the stage? Thanks.

like image 420
Alexandr Avatar asked Jul 28 '15 14:07

Alexandr


1 Answers

What's happening is that the shadow is being clipped off at the edge of the stage. If your root node is an instance of Region (which includes all the layouts) you can add padding.

region.setPadding(new Insets(20,20,20,20));

Then the drop shadow should appear. If the CSS doesn't work, you can also add the drop shadow in the code itself with:

stage.getScene().getRoot().setEffect(new DropShadow());

Edit: The scene will need to be transparent as well.

stage.getScene().setFill(Color.TRANSPARENT);
like image 94
Cameron Tauxe Avatar answered Nov 16 '22 05:11

Cameron Tauxe