DropShadow class is a part of JavaFX. DropShadow class creates a high-level effect that renders the shadow of an object behind the content with the specified radius, spread, blur type and offset. DropShadow class inherits Effect class.
Constructors of the class:
- DropShadow(): Creates a new object of DropShadow.
- DropShadow(BlurType blurType, Color color, double radius, double spread, double offsetX, double offsetY): Creates a new object of DropShadow with specified values blurType, radius, spread, offsetX, offsetY.
- DropShadow(double radius, Color color): Creates a new object of DropShadow with specified value of radius and color.
- DropShadow(double radius, double offsetX, double offsetY, Color color): Creates a new object of DropShadow with specified value of radius, offsetX, offsetY and color.
Commonly Used Methods:
| Method | Explanation |
|---|---|
| getBlurType() | Returns the blur type of the effect. |
| getColor() | Returns the color of the effect. |
| getInput() | Returns the value of property input. |
| getRadius() | Returns the radius of the dropShadow effect. |
| setBlurType(BlurType v) | Sets the blur type of the dropShadow effect. |
| setColor(Color v) | Sets the Color of the dropShadow effect. |
| setInput(Effect v) | Sets the value of the property input. |
| setRadius(double v) | Sets the Radius of the dropshadow effect. |
| setOffsetX(double v) | Sets the value of offsetX. |
| setOffsetY(double v) | Sets the value of offsetY. |
| getOffsetX() | Returns the value of offsetX. |
| getOffsetY() | Returns the value of offsetY. |
| getSpread() | Returns the value of spread of drop Shadow effect. |
| setSpread(double v) | Sets the value of spread of drop Shadow effect. |
Below programs illustrate the use of DropShadow class:
- Java program to create a Circle and add DropShadow effect to it: In this program we will create a Circle named circle and create a DropShadow effect drop_shadow with specified radius and color. The DropShadow effect will be added to the circle using the setEffect() function and the circle will be added to the group. The circles will be translated to specific position in the stage using setTranslateX() and setTranslateY() function. The group will be added to the scene and the scene will be added to the stage.
// Java program to create a Circle and// add DropShadow effect to itimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.image.*;importjavafx.scene.effect.*;importjava.io.*;importjavafx.scene.shape.Circle;importjavafx.scene.paint.Color;importjavafx.scene.Group;ÂÂpublicclassdrop_shadow_1extendsApplication {   Â// launch the application   Âpublicvoidstart(Stage stage)throwsException   Â{       Â// set title for the stage       Âstage.setTitle("drop_shadow example");       Â// create a circle       ÂCircle circle =newCircle(50.0f,50.0f,25.0f);       Â// set fill for circle       Âcircle.setFill(Color.BLUE);       Â// translate to a position       Âcircle.setTranslateX(50.0f);       Âcircle.setTranslateY(50.0f);       Â// create a drop_shadow effect       ÂDropShadow drop_shadow =newDropShadow(10, Color.RED);       Â// set effect       Âcircle.setEffect(drop_shadow);       Â// create a Group       ÂGroup group =newGroup(circle);       Â// create a scene       ÂScene scene =newScene(group,200,200);       Â// set the scene       Âstage.setScene(scene);       Âstage.show();   Â}   Â// Main Method   Âpublicstaticvoidmain(String args[])   Â{       Â// launch the application       Âlaunch(args);   Â}}Output:
- Java program to create four Circles and add DropShadow effect to it, which are of different blur types and different values of offsetX, offsetY and radius: In this program we will create Circles named circle, circle1, circle2, circle3 and create a DropShadow effects named drop_shadow1, drop_shadow2, drop_shadow3, drop_shadow4 with specified radius, color, offsetX, offsetY, spread and blur type. The DropShadow effect will be added to the circle using the setEffect() function and the circles will be added to the group. The circles will be translated to specific position in the stage using setTranslateX() and setTranslateY() function. The group will be added to the scene and the scene will be added to the stage.
// Java program to create four Circles andÂ// add DropShadow effect to it which are of// different blur types and different valuesÂ// of offsetX, offsetY and radiusimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.image.*;importjavafx.scene.effect.*;importjava.io.*;importjavafx.scene.shape.Circle;importjavafx.scene.paint.Color;importjavafx.scene.Group;ÂÂpublicclassdrop_shadow_2extendsApplication {   Â// launch the application   Âpublicvoidstart(Stage stage)throwsException   Â{       Â// set title for the stage       Âstage.setTitle("drop_shadow example");       Â// create a circle       ÂCircle circle =newCircle(0.0f,0.0f,25.0f, Color.RED);       ÂCircle circle1 =newCircle(0.0f,0.0f,25.0f, Color.RED);       ÂCircle circle2 =newCircle(0.0f,0.0f,25.0f, Color.RED);       ÂCircle circle3 =newCircle(0.0f,0.0f,25.0f, Color.RED);       Â// translate to a position       Âcircle.setTranslateX(50.0f);       Âcircle.setTranslateY(50.0f);       Â// translate to a position       Âcircle1.setTranslateX(150.0f);       Âcircle1.setTranslateY(50.0f);       Â// translate to a position       Âcircle2.setTranslateX(50.0f);       Âcircle2.setTranslateY(150.0f);       Â// translate to a position       Âcircle3.setTranslateX(150.0f);       Âcircle3.setTranslateY(150.0f);       Â// create drop_shadow effect       ÂDropShadow drop_shadow1 =newDropShadow(BlurType.values()[0],                                    ÂColor.BLUE,5,3.0f,2.0f,2.0f);       ÂDropShadow drop_shadow2 =newDropShadow(BlurType.values()[1],                                    ÂColor.BLUE,5,3.0f,3.0f,3.0f);       ÂDropShadow drop_shadow3 =newDropShadow(BlurType.values()[2],                                    ÂColor.BLUE,5,4.0f,3.0f,3.0f);       ÂDropShadow drop_shadow4 =newDropShadow(BlurType.values()[3],                                    ÂColor.BLUE,5,4.0f,2.0f,2.0f);       Â// set effect       Âcircle.setEffect(drop_shadow1);       Âcircle1.setEffect(drop_shadow2);       Âcircle2.setEffect(drop_shadow3);       Âcircle3.setEffect(drop_shadow4);       Â// create a Group       ÂGroup group =newGroup(circle, circle1, circle2, circle3);       Â// create a scene       ÂScene scene =newScene(group,400,400);       Â// set the scene       Âstage.setScene(scene);       Âstage.show();   Â}   Â// Main Method   Âpublicstaticvoidmain(String args[])   Â{       Â// launch the application       Âlaunch(args);   Â}}Output:
Note: The above programs might not run in an online IDE. Please use an offline compiler.
Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/DropShadow.html

