How to add an inner shadow effect to a text node in JavaFX?

You can add an effect to any node object in JavaFX using the setEffect() method. This method accepts an object of the Effect class and adds it to the current node.

javafx.scene.effect.InnerShadow class represents the inner shadow effect. This effect renders the shadow of the given content inside its edges, with the specified parameters (color, offset, radius).

To add a reflection effect to a text node −

  • Instantiate the Text class bypassing basic the x, y coordinates (position), and text string as arguments to the constructor.

  • Set desired properties like font, stoke, etc.

  • Create the inner shadow effect by instantiating the InnerShadow class.

  • Set the created effect to the text node using the setEffect() method.

  • Finally, add the created text node to the Group object.


import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.InnerShadow;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class InnerShadowEffectExample extends Application {
   public void start(Stage stage) throws FileNotFoundException {
      //Creating a text object
      String str = "Tutorialspoint";
      Text text = new Text(30.0, 100.0, str);
      //Setting the font
      Font font = Font.font("Brush Script MT", FontWeight.BOLD, 110);
      //Setting color of the text
      //Creating the inner shadow effect
      InnerShadow shadow = new InnerShadow();
      //Setting the effect to the text
      //Setting the stage
      Group root = new Group(text);
      Scene scene = new Scene(root, 595, 150, Color.BEIGE);
      stage.setTitle("Inner Shadow Effect");
   public static void main(String args[]){