×

JavaFX Inner Shadow

In the JavaFX application, in order to apply various Inner Shadow effect, we use this class. It has the ability to create the inner shadow of the given object. This effect is some what similar to shadow effect but only difference is it creates the shadow inside the edges of the node. All methods needed for this purpose are present in the javafx.scene.effect.InnerShadow class.

Properties and corresponding methods to create Inner 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 is double type property. 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 is double type property. It is used to represent the radius of the shadow effect and the setRadius( Double value ) method is used to set it.

5. choke       

This is double type property. It is used to represent the choke parameter of the shadow effect and the setChoke( 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 is double type property. 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 is double type property. It is used to represent the y coordinate of the shadow and the setOffsetY( Double value ) method is used to set it.

Constructors to create Inner Shadow Effect :

  • public InnerShadow() : 

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

  • public InnerShadow(double radiusValue, Color colorvalue) :

This constructor is used to create the new constructor with the specified radius and color parameters.

  • public InnerShadow(double radiusValue, double offsetX, double offsetY, Color colorvalue) : 

This constructor is used to create the new constructor with the specified radius, offset x and offset y and color parameters.

  • public InnerShadow(BlurType blurtype, Color colorvalue, double radiusValue, double choke, double offsetX, double offsetY) :

This constructor is used to create the new constructor with the specified radius, blur type, choke, offset x and offset y and color parameters.

JavaFX Effect – Image with and without Inner Shadow Effect :

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.InnerShadow;
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");
        
        ImageView newimageView = 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); 




         
        InnerShadow shadow = new InnerShadow();  
        shadow.setBlurType(BlurType.GAUSSIAN);  
        shadow.setColor(Color.BLUE);  
        shadow.setHeight(25);  
        shadow.setRadius(12);  
        shadow.setWidth(20);  
        shadow.setChoke(0.9);  
        newimageView2.setEffect(shadow);              
         Group root = new Group(newimageView,newimageView2);  


      Scene scene = new Scene(root,800,400);  
         stage.setScene(scene);  
        stage.setTitle(" JavaFx Inner shadow Effect example ");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create image with and without Inner 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.InnerShadow, 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 named EffectUI 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 Inner 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 Inner 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 Inner Shadow Effect example”. Also, it displays the image with and without Inner Shadow Effect.

JavaFX Effect – Inner Shadow

Related Topics

JavaFX Light Point

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

4 minutes read.

JavaFX Translate Transition

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

3 minutes read.

JavaFX Tutorial

Introduction of JavaFX: The most popular applications called Rich Internet Application are build using the JavaFX. This application can run across many platforms. Various devices such as mobile, computers, and tablets...

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 Bubble Chart

In the JavaFX application, in order to create Bubble Chart, the BubbleChart class is used. The Bubble Chart allows us to plot three dimensional data. All methods needed for this...

4 minutes read.

JavaFX Fill Transition

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

4 minutes read.

JavaFX File Chooser

In the JavaFX application, in order to open or save the file, FileChooser is used. It allows user to choose the file from system location and save it in a...

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 RadioButton

In the JavaFX application, to get the user information in the form of choice from the user, a form is created using radio buttons that allow the user to select...

3 minutes read.

JavaFX Transformation

In the JavaFX application, in order to apply various transformation effects, we use Transform class. It has the ability to create the transformation on the given object. This transformation changes...

3 minutes read.

JavaFX Menu

In the JavaFX application, in order to create a menu, menu items, and menu bar, Menu, MenuItem, and MenuBar class is used. The menu allows us to choose options among...

4 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Parallel Transition

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

4 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 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 Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. 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 Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 minutes read.

JavaFX Arc

In the JavaFX application, in order to draw an arc, the Arc class is used. The Arc allows us to join any points in the space. All methods needed for...

5 minutes read.

JavaFX Slider

In the JavaFX application, in order to slide over a range of data having values, Slider is used. It provides a pane with a Slider to move over a range...

4 minutes read.