Table of contents
1.
Introduction
2.
Inner Shadow Class
3.
Constructors
4.
Properties
5.
Sample Program
6.
Frequently Asked Questions
6.1.
What is a class?
6.2.
What is the ‘extends’ keyword?
6.3.
What is the ‘scene’ class?
6.4.
What is a package?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

JavaFX InnerShadow

Author Manish Kumar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Hey Ninja!! You must have used pastel colours in your childhood to colour pictures of outlined drawings. Imagine colouring the outermost boundaries from the inner side. This is the exact effect the inner shadow class creates. 

In this blog, you will learn about the inner shadow class, its constructors, and properties, and you will also go through a sample program to understand the implementation of the inner shadow class. Let's jump right into the details of this excellent class.

JavaFX Logo

Inner Shadow Class

Inner Shadow class is a part of JavaFX and is present under the javafx.scene.effect package. On applying the inner shadow, a blur effect is created along the inside edges of the node.  In the sample program given below, the inner shadow effect of the GAUSSIAN blur type is made with the HOTPINK colour.

Constructors

There are four constructors in the class:

  1. InnerShadow (): It creates a new object with default parameters.
  2. InnerShadow (radius, colour): It creates a new object with specified colour and radius.
  3. InnerShadow (radius, offsetX,offsetY, colour): It creates a new object with the selected colour, radius and offset in x and y directions.
  4. InnerShadow (blur type, colour, radius, choke, offsetX, offsetY): It creates a new object with the selected colour, radius and offset in x and y directions, blur type and choke

Properties

InnerShadow class offers various properties to manage the state of the object. They are listed below:
 

                        Table of properties


Sample Program

Let us go through a sample program to understand the implementation of the inner shadow class. Here we will take a picture of a ninja and apply an inner shadow effect to it:

//Code to show implementation of inner shadow effect in JavaFX
//Coding Ninjas
package com.example.javafx_inner_shadow_coding_ninjas;

//Import statements to fetch various pre written classes
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;

//Main class to implement inner shadow
public class CodingNinjas extends Application {
   //start method custom definition
   @Override
   public void start(Stage view)
   {
       //Creating new image object
       Image pic = new Image("C:/Users/kvoxa/Downloads/ninja.png");
       
       //Creating new image view objects
       ImageView picView1 = new ImageView(pic);
       ImageView picView2 = new ImageView(pic);
       
       //Defining coordinates of image views
       picView1.setX(120);
       picView1.setY(70);
       picView2.setX(400);
       picView2.setY(70);
       picView1.setFitHeight(150);
       picView1.setFitWidth(300);
       picView2.setFitHeight(150);
       picView2.setFitWidth(300);
       picView1.setPreserveRatio(true);
       picView2.setPreserveRatio(true);
       
       //Creating inner shadow object
       InnerShadow shade = new InnerShadow();
       shade.setBlurType(BlurType.GAUSSIAN);
       shade.setColor(Color.HOTPINK);
       shade.setHeight(25);
       shade.setRadius(12);
       shade.setWidth(20);
       shade.setChoke(0.9);
       picView2.setEffect(shade);
       
       //Creating new group object
       Group root = new Group(picView1,picView2);
       
       //Setting up scene and configuring view
       Scene scene = new Scene(root,800,400);
       view.setScene(scene);
       view.setTitle(" JavaFx Inner shadow Effect : Coding Ninjas ");
       view.show();
   }
   // main launch method
   public static void main(String[] args) {
       launch(args);
   }
}
You can also try this code with Online Java Compiler
Run Code

 

Output:

Output of Sample Program

Frequently Asked Questions

What is a class?

A class is a common template to specify common methods and properties of objects.

What is the ‘extends’ keyword?

The ‘extends’ keyword is used to inherit from another class.

What is the ‘scene’ class?

It is the container for all objects of the scene graph and requires the root object to work.

What is a package?

A package is a namespace similar to a folder where you can put your source files. It organises related classes and interfaces. You might keep java code in one folder, images in another, etc.

Conclusion

Finally, you have made it to the end of this article. Congratulations!! In this blog, you learned about InnerShadow class in JavaFX. You went through the class, its constructors, and a sample program.

After reading about the inner shadow class in JavaFX, are you not feeling excited to read more articles on the topic of JavaFX? Don't worry; Coding Ninjas has you covered. To learn, see the JavaFX ShadowJavaFX Scatter ChartJavaFX Bar ChartJavaFX Stacked Area Chart etc.

Please refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. And also, enrol in our courses and refer to the mock test and problems available. Have a look at the interview experiences and interview bundle for placement preparations.

Please do upvote our blogs if you find them helpful and informative!

Ninja Image

Happy learning!

Live masterclass