- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add a reflection 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.
The reflection effect renders the reflection of the given content below it. The javafx.scene.effect.Reflection represents the reflection effect. To add a blur 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 a blur effect by instantiating the Reflection class.
Set the created effect to the text node using the setEffect() method.
Finally, add the created text node to the Group object.
Example
import java.io.FileNotFoundException; 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.FontPosture; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; public class ReflectionEffect extends Application { public void start(Stage stage) throws FileNotFoundException { //Creating a text object String str = "Welcome to Tutorialspoint"; Text text = new Text(30.0, 80.0, str); //Setting the font Font font = Font.font("Brush Script MT", FontWeight.BOLD, FontPosture.REGULAR, 65); text.setFont(font); //Setting the color of the text text.setFill(Color.BROWN); //Setting the width and color of the stroke text.setStrokeWidth(2); text.setStroke(Color.BLUE); //Creating the reflection effect Reflection reflection = new Reflection(); reflection.setFraction(0.8); //Setting the effect to the text text.setEffect(reflection); //Setting the stage Group root = new Group(text); Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Reflection Effect"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
- Related Articles
- How to add a blur effect to a text node in JavaFX?
- How to add a drop shadow effect to a text node in JavaFX?
- How to add an inner shadow effect to a text node in JavaFX?
- How to create text node in JavaFX?
- How to set font to text node in JavaFX?
- How to add custom fonts to a text in JavaFX?
- How to add shadow Effect for a Text in Android?
- How to rotate a node in JavaFX?
- How to add a combination of multiple effects to text in JavaFX?
- How to add various fonts to text using text flow in JavaFX?
- How to add stroke and color to text in JavaFX?
- How to adjust the line spacing in the text node in JavaFX?
- How to add LCD (liquid crystal display) to text in JavaFX?
- How to apply linear gradient (color) to a node in JavaFX?
- How to apply radial gradient (color) to a node in JavaFX?

Advertisements