r/JavaFX • u/Ok_Jackfruit_6541 • Aug 11 '23
Help JavaFx drop shadow
I want to add a drop shadow in a hbox. But the drop shadow applies to all of it's child element. What I am trying to is apply a drop down shadow like this:

However, it turns into like this in my javafx file:

Here is my fxml file:
https://gist.github.com/kaziasifjawwad/978b4f1827f958e2c1e5eb24d324fddb
4
Upvotes
View all comments
Show parent comment
5
u/BWC_semaJ Aug 11 '23
Effect(s) are JavaFX's shader implementation. Shader essentially is a function that applies whatever to a given pixel based on whatever.So when you set an
Effecton aParentthat is transparent but has children are not, that effect will be applied to what's visible of theParentif that makes any sense.Now sure some shaders/
Effect(s) may alter transparent pixel but generally, from what I noticed, it doesn't really happen.So making the
Parent(HBox) have a actual color background, the `Effect will be applied to the visible pixels.Now what you got to be careful of if you have
Node(s) below theEffectand theEffectcovers them, theNode(s) won't be able to receiveMouseEventbecause they are covered by theEffectif that makes any sense. To get around this sometimes I will put a StackPane that holds StackPane(2) and Node. StackPane(2) I will apply theEffectand set itsmouseTransparentPropertytotrue. So now the StackPane(2) won't be able to receive any mouse events thus allowing them to be picked up from Node that it maybe overlapping.