JavaFX Effects - Reflection

On applying the reflection effect to a node in JavaFX, a reflection of it is added at the bottom of the node.

The class named Reflection of the package javafx.scene.effect represents the reflection effect. This class contains four properties, which are −

  • topOpacity − This property is of double type representing the top extremes opacity value of the reflection.

  • bottomOpacity − This property is of double type representing the bottom extremes opacity value of the reflection.

  • input − This property is of the type Effect and it represents an input to the reflection effect.

  • topOffset − This property is of double type representing the distance between the bottom of the input and the top of the reflection.

  • fraction −This property is of double type representing the fraction of input that is visible in the output. The range of the fraction value is 0.0 to 1.0.


The following program is an example demonstrating the reflection effect. In here, we are drawing the text “Welcome to Tutorialspoint” filled with DARKSEAGREEN color and applying the reflection effect to it.

Save this code in a file with the name

import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.scene.effect.Reflection; 
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 ReflectionEffectExample extends Application { 
   public void start(Stage stage) {       
      //Creating a Text object 
      Text text = new Text();       
      //Setting font to the text 
      text.setFont(Font.font(null, FontWeight.BOLD, 40));       
      //setting the position of the text 
      //Setting the text to be embedded. 
      text.setText("Welcome to Tutorialspoint");       
      //Setting the color of the text 
      //Instanting the reflection class 
      Reflection reflection = new Reflection(); 
      //setting the bottom opacity of the reflection 
      //setting the top opacity of the reflection 
      //setting the top offset of the reflection 
      //Setting the fraction of the reflection 
      //Applying reflection effect to the text 
      //Creating a Group object  
      Group root = new Group(text);   
      //Creating a scene object 
      Scene scene = new Scene(root, 600, 300);  
      //Setting title to the Stage 
      stage.setTitle("Reflection effect example"); 
      //Adding scene to the stage 
      //Displaying the contents of the stage;         
   public static void main(String args[]){ 

Compile and execute the saved java file from the command prompt using the following commands.

java ReflectionEffectExample   

On executing, the above program generates a JavaFX window as shown below.

Reflection Effect