Introduction
The JavaFX MotionBlur class is used to apply various motion blur effects. MotionBlur is a JavaFX effect that blurs the nodes, much like Gaussian Effect does. It also employs a Gaussian Convolution Kernel, which contributes to the blurring effect. The main difference between Gaussian Effect and Motion Blur is that the Gaussian Convolution Kernel is used at a specific angle with the Gaussian Effect.
As the name implies, this effect causes the node to appear to be in motion. The motion blur effect is represented by javafx.scene.effect.MotionBlur class. This class must be instantiated in order to produce the desired effect.
Constructors
There are two different types of constructors available in the motion blur:
-
public MotionBlur(): Creates a new MotionBlur object with the default values.
- public MotionBlur(double angle, double radius): Creates a new MotionBlur object with the specified angle and radius.
Properties
The table below describes the MotionBlur class properties as well as the setter methods.

Usage
This program serves as an example of the Motion Blur Effect. In this case, we're drawing the text "Welcome to Coding Ninjas" in Grey and applying the Motion Blur Effect at a 45-degree angle to it.
Put this code in a file called MotionBlurEffectExample.java.
Implementation
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.scene.text.FontWeight;
import javafx.scene.effect.MotionBlur;
import javafx.scene.text.Text;
public class MotionBlurEffectExample extends Application {
@Override
public void start(Stage stage) {
//Create a Text object
Text text = new Text();
//Setting the font
text.setFont(Font.font(null, FontWeight.BOLD, 40));
//setting the position of the text
text.setX(60);
text.setY(150);
//Setting the text to be added.
text.setText("Welcome to Coding Ninjas");
//Set the color of the text
text.setFill(Color.GREY);
//Instantiating the MotionBlur class
MotionBlur motionBlur = new MotionBlur();
//Setting the radius and angle to the effect
motionBlur.setRadius(10.5);
motionBlur.setAngle(45);
//Applying MotionBlur effect to text
text.setEffect(motionBlur);
//Creating a Group object
Group root = new Group(text);
//Creating a scene object
Scene scene = new Scene(root, 600, 300);
stage.setTitle("Imageinput effect example");
//Adding scene to the stage
stage.setScene(scene);
//Displays the content
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
How to execute the above program?
To execute the above program. You can follow the given steps:
-
Open the terminal in the same folder where you have saved your source code.
-
Enter the below code and hit enter.
javac --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
After you hit enter a new file will automatically be generated namely yourFilename.class
-
Now, enter the below command and hit enter to execute the above program.
java --module-path path/to/your/javaFx/modules --add-modules javafx.fxml,javafx.controls filename.java
-
You have successfully executed the JavaFX program.
Output





