You can apply Special Effects to any Node using the setEffect() method. For example, the code below adds a DropShadow effect to a Text node and Circle node.
// Create a special effect
DropShadow dropShadow = new DropShadow(5, 5, 5, Color.GRAY);
// Create a Text node and Circle node
Text text = new Text(10, 70, "JavaFX drop shadow!");
text.setFont(new Font("Arial", 40));
Circle circle = new Circle(50, 125, 30);
circle.setFill(Color.STEELBLUE);
// Apply the special effect to our Nodes
text.setEffect(dropShadow);
circle.setEffect(dropShadow);
Here's a visual guide to some of the Effects in the Effect Package. Try them out by reading the API for the Effect you're interested in.
You can chain together multple effects by making one Effect the input to another Effect. To pass one Effect into another, use the setInput() method. For example, the code below adds a GaussianBlur to a DropShadow.
// Create some special effect
DropShadow dropShadow = new DropShadow(5, 5, 5, Color.GRAY);
GaussianBlur blur = new GaussianBlur(10);
// Create a Text node
Text text = new Text(10, 70, "JavaFX blur and shadow!");
text.setFont(new Font("Arial", 40));
// Chain the effects by making one the input to the other
blur.setInput(dropShadow);
// Apply the base effect to the node
text.setEffect(blur);
Last modified: March 13, 2023