Want to add drop shadow only to the border of Grid pane not to inner child elements
here is the image of screen showing the effect.
Want to add drop shadow only to the border of Grid pane not to inner child elements
here is the image of screen showing the effect.
Use a StackPane and place your GridPane in it.
Style your StackPane with CSS to apply a background color, insets and a drop shadow.
See Drop Shadow in an undecorated Pane! JAVAFX for some sample CSS.
Here is a small standalone sample app (used Java 8b120 on OS X 10.9), to demonstrate the effect:
Addressing additional questions
No, this could be done in code instead of CSS, by using the DropShadow effect.
Because setting a background provides a clear edge to the node to which the shadow effect is applied.
There is no real differing behavior in the drop shadow processing between a root node or nested container. The drop shadow effect depends on whether the item having the effect applied has a transparent (or null) background or not. Note though that a root node usually fills a stage. So, if the root node has a non-transparent background color and no insets are supplied, then the shadow on the root node will not be seen as it will fall outside the visible area of the stage.
I'll offer a guess at what is happening. I think what the drop shadow effect is doing is calculating the exterior shape of the node, then applying the shadow to it. When that node has a background color, then the you will see the shadow of the node background, which is what is seen in the image supplied. If the node has no background color, then the edges of the nodes are calculated from the child nodes, so all of the children get shadows.
Now what happened is that between JavaFX 2.2 when the question was asked and JavaFX 8, the default theme for JavaFX moved from Caspian to Modena. With Caspian panes did not have any background color by default. However for Modena, panes do have a slight off-white background color by default. This means that the original poster's blurry text inside the grid pane won't occur by default in Java 8, as the GridPane will have a background which is shadowed, instead of interior text being shadowed. This can be verified via the running the following program and varying the commented out line for setting the stylesheet to Caspian:
jewelsea's answer is correct, but please note that it does not work when
or
This can be really frustrating if you are trying to apply the drop shadow to the (Stack)Pane's entire bounding box area and not it's child contents! Setting a non-transparent background color works, but if you have many elements side by side or on top of each other (i.e. close together), you may see undesirable overlap effects with the drop shadows.