How to add shadow to window in JavaFX?


Question

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.

1
5
8/29/2012 5:58:08 PM

Accepted Answer

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

6
8/29/2012 11:49:08 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon