×

JavaFX Drop Shadow

In the JavaFX application, in order to apply various Drop Shadow effect, we use this class. It has the ability to create the drop shadow of the given object. This effect is some what similar to shadow effect but only difference is it creates the duplicate of the original node and produces shadow according to the given parameters. All methods needed for this purpose are present in the javafx.scene.effect.DropShadow class.

Properties and corresponding methods to createDrop Shadow Effect :

1. height       

This property is of double type. It is used to represent the vertical size of the shadow blur kernel and the setHeight( Double value ) method is used to set it.

2. width

This property is of double type. It is used to represent the horizontal size of the shadow blur kernel and the setWidth( Double value ) method is used to set it.

3. input       

This property is of effect type. It is used to represent the input for the effect and the setInput( Effect value ) method is used to set it.

4. radius

This property is of double type. It is used to represent the radius of the shadow effect and the setRadius( Double value ) method is used to set it.

5. Spread     

This property is of double type. It is used to represent the spread parameter of the shadow and the setSpread( Double value ) method is used to set it.

6. blurType

This property is of blur type. It is used to represent the algorithm used for blur the shadow and the setBlurType( BlurType value ) method is used to set it.

7. offsetX

This property is of double type. It is used to represent the x coordinate of the shadow and the setOffsetX( Double value ) method is used to set it.

8. offsetY

This property is of double type. It is used to represent the y coordinate of the shadow and the setOffsetY( Double value ) method is used to set it.

Constructors to createDrop Shadow Effect:

  • public DropShadow() : 

This constructor is used to create the new empty constructor with the default parameters.

  • public DropShadow(double radiusValue, Colorcolorvalue) :

This constructor is used to create the new constructor with the specifiedradius and colorparameters.

  • public DropShadow(double radiusValue, double offsetX, double offsetY, Colorcolorvalue) : 

This constructor is used to create the new constructor with the specifiedradius, offset x and offset y and colorparameters.

  • public DropShadow(BlurTypeblurtype, Colorcolorvalue, double radiusValue, double spread, double offsetX, double offsetY) :

This constructor is used to create the new constructor with the specifiedradius, blur type, spread, offset x and offset y and colorparameters.

JavaFX Effect – Image with and without Drop Shadow Effect :

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Shadow;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 


Image newimage = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");


ImageViewnewimageView = new ImageView(newimage); 
Image newimage2 = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");


ImageView newimageView2 = new ImageView(newimage); 


newimageView.setX(140);  
newimageView.setY(90); 
        newimageView2.setX(440);  
        newimageView2.setY(90); 


newimageView.setFitHeight(200); 
newimageView.setFitWidth(400); 
        newimageView2.setFitHeight(200); 
        newimageView2.setFitWidth(400); 


newimageView.setPreserveRatio(true); 
        newimageView2.setPreserveRatio(true); 


DropShadow shadow = new DropShadow();  
shadow.setBlurType(BlurType.GAUSSIAN);  
shadow.setColor(Color.GREY);  
shadow.setHeight(150);  
shadow.setWidth(100);  
shadow.setOffsetX(20);  
shadow.setOffsetY(20);  
shadow.setSpread(0.3);  
shadow.setRadius(20);  
        newimageView2.setEffect(shadow);              
         Group root = new Group(newimageView,newimageView2);  


  Scene scene = new Scene(root,800,400);  
stage.setScene(scene);  
stage.setTitle(" JavaFx Drop shadow Effect example ");  
stage.show();  
     }

    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create image with and without Drop Shadow Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.DropShadow, javafx.scene.paint.Color, javafx.scene.effect.BlurType, javafx.scene.image.Image, javafx.scene.image.ImageView, javafx.stage.Stage.

Then we have created one class namedEffectUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold the image with and without Drop Shadow Effect, a Group object is created which is then passed to the Scene class object.

The image is created using the constructor and various properties are set using setters. The Drop Shadow constructor is created and then using the setEffect, the effect is applied on one image and the other image is kept as it is.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, "JavaFX Drop Shadow Effect example”. Also, it displays the image with and without Drop Shadow Effect.

JavaFX Effect – Drop Shadow

Related Topics

JavaFX ID selector

In the JavaFX application, in order to apply various css effect using the id selector, we use the various css classes available in the JavaFX. This is generally used to...

4 minutes read.

JavaFX Sequential Transition

In the JavaFX application, in order to generate the sequential transition, we have to apply sequential transition on any particular shape. It has the ability to execute multiple transactions sequentially...

4 minutes read.

JavaFX Rotate Transition

In the JavaFX application, in order to generate the rotate transition, we have to apply rotation transition on any particular shape. It has the ability to rotate the shape along...

4 minutes read.

JavaFX Box

In the JavaFX application, in order to draw a Box, the Box class is used. The Box allows us to form 3D shape having rectangular faces. All methods needed for...

4 minutes read.

JavaFX HyperLink

In the JavaFX application, in order to access and use webpages, hyperlinks are used. In HTML anchor tags are used in the same way in JavaFX hyperlinks are used. To...

4 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX Layouts

Layouts in the JavaFX application are treated as a container for different UI elements such as Button, Label, TextArea, etc. Layouts are used as parent container. The layout is used...

3 minutes read.

JavaFX Light Spot

In the JavaFX application, in order to apply various Light Spot effect from a single source, we use this class. It has the ability to apply light from all the...

4 minutes read.

JavaFX Pause Transition

In the JavaFX application, in order to generate the pause transition, we have to apply pause transition on any particular shape. It has the ability to take a particular pause...

4 minutes read.

JavaFX ProgressBar

In the JavaFX application, in order to show the progress of work ProgressBar is used. It shows how much work is done. In order to use ProgressBar in JavaFX, javafx.scene.control.ProgressBar...

4 minutes read.

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

4 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

5 minutes read.

JavaFX Button

The button is one of the UI control present in the JavaFX. The javafx.scene.control.Button class is used for creating a button in javafx example. It is also possible to create...

5 minutes read.

JavaFX Motion Blur

In the JavaFX application, in order to apply various Motion blur effect, we use Motion Blur class. It has the ability to apply the Motion blur effect on the given...

4 minutes read.

JavaFX Line Chart

In the JavaFX application, in order to create a Line Chart, LineChart class is used. The LineChart allows us to plot markers point according to the entities on number axes....

4 minutes read.

JavaFX BorderPane

In the JavaFX application, in order to set Border Pane as a layout, the BorderPane class is used. The BorderPane layout allows us to arrange the components in the left,...

4 minutes read.

JavaFX Blend

In the JavaFX application, in order to apply various blend effect, we use Blend class. It has the ability to blend the colors of the shape. All methods needed for...

4 minutes read.

JavaFX Line

In the JavaFX application, in order to draw a line, the Line class is used. The line allows us to join any two points with x and y coordinates in...

3 minutes read.

JavaFX TilePane

In the JavaFX application, in order to set TilePane as a layout, the TilePane class is used. The TilePane layout allows us to arrange the components in the same sized...

4 minutes read.