Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add shadow to window in JavaFX?

Tags:

java

javafx

I have removed the default borders around the primary stage:

stage.initStyle(StageStyle.UNDECORATED)

This removes the window borders which is what I want, but now I'd like to have a drop shadow under the window.

The top level BorderPane object has a dropshadow effect applied, but the shadow is cut off:

enter image description here

You can see the shadow slightly on the bottom right, but as soon as the main application area ends the shadow is cut off.

like image 597
Tower Avatar asked Aug 29 '12 17:08

Tower


People also ask

What is drop shadow in JavaFX?

Property description: The radius of the shadow blur kernel. This attribute controls the distance that the shadow is spread to each side of the source pixels. Setting the radius is equivalent to setting both the width and height attributes to a value of (2 * radius + 1) .


1 Answers

I created an example for this earlier. Use the specific revision linked as in later revisions I dropped the shadow effect from the dialog.

The sample places the stage content in a StackPane containing two panes. The shadow is only applied to the background Pane and the dialog content is placed in a top pane. The background of the top pane is slightly inset from the bottom pane so that the background and shadow can show through.

Further discussion is in a thread on displaying a shadow around an undecorated/transparent stage.

Sample shadowed dialog

like image 157
jewelsea Avatar answered Sep 23 '22 19:09

jewelsea