×

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods needed for this purpose are present in the javafx.scene.effect.GaussianBlur class.

Properties and corresponding methods to createGaussian Blur Effect :

1. input

This propertyis of Effect type. It is used to represent the input required for the gaussian blur effect and the setInput( Effect value ) method is used to set it.

2. radius

This property is of double type. It is used to represent the radius of the gaussian blur effect kernel and the setRadius( Double value) method is used to set it.

JavaFX Effect – Gaussian Blur Effect

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 


Text text = new Text();  
         text.setText(" Text With Gaussian Blur Effect ");  
         text.setX(100);  
         text.setY(100);  
         text.setFont(Font.font("Times New Roman",FontWeight.BLACK,FontPosture.ITALIC,30));  
         text.setFill(Color.RED);  
         text.setStroke(Color.BROWN);  
         text.setUnderline(true);  
         GaussianBlur g = new GaussianBlur();  
         g.setRadius(5);  
         text.setEffect(g);  
         Group root = new Group();  
         root.getChildren().add(text);  
    Scene scene = new Scene(root,600,300);  
         stage.setScene(scene);  
        stage.setTitle(" JavaFx Gaussian Blur Effect example ");  
         stage.show();  
     }

    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

JavaFX Effect – Gaussian Blur

Explanation:

In order to create Gaussian Blur Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.GaussianBlur, javafx.scene.paint.Color, javafx.scene.text.Font, javafx.scene.text.FontPosture, javafx.scene.text.FontWeight, javafx.scene.text.Text, javafx.stage.Stage.

Then we have created one class named EffectUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold text with Gaussian blur effect, a Group object is created which is then passed to the Scene class object.

The text is created using the constructor and various properties are set using setters. The Gaussian blur constructor is created and then using the setEffect, the effect is applied to the text.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, "JavaFX Gaussian Blur Effect example". Also, it displays the text with the Gaussian blur effect.

JavaFX Effect – Text with and without Gaussian Blur Effect :

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 


Text text = new Text();  
    text.setText(" Text With Gaussian Blur Effect ");  
         text.setX(100);  
         text.setY(100);  
         text.setFont(Font.font("Times New Roman",FontWeight.BLACK,FontPosture.ITALIC,30));  
         text.setFill(Color.RED);  
         text.setStroke(Color.BROWN);  
         text.setUnderline(true);  




         Text text2 = new Text();  
         text2.setText(" Text Without Gaussian Blur Effect ");  
         text2.setX(100);  
         text2.setY(150);  
         text2.setFont(Font.font("Times New Roman",FontWeight.BLACK,FontPosture.ITALIC,30));  
         text2.setFill(Color.RED);  
         text2.setStroke(Color.BROWN);  
         text2.setUnderline(true);  


         GaussianBlur g = new GaussianBlur();  
         g.setRadius(5);  
         text.setEffect(g);  


         Group root = new Group(text,text2);  


  Scene scene = new Scene(root,600,300);  
         stage.setScene(scene);  
        stage.setTitle(" JavaFx Gaussian Blur Effect example ");  
         stage.show();  
     }

    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

JavaFX Effect – Gaussian Blur

Explanation:

In order to create text with and without Gaussian Blur Effect in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.GaussianBlur, javafx.scene.paint.Color, javafx.scene.text.Font, javafx.scene.text.FontPosture, javafx.scene.text.FontWeight, javafx.scene.text.Text, javafx.stage.Stage.

Then we have created one class named EffectUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold text with and without Gaussian Blur Effect, a Group object is created which is then passed to the Scene class object.

The text is created using the constructor and various properties are set using setters. The Gaussian blur constructor is created and then using the setEffect, the effect is applied on one text and the other text is kept as it is.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, "JavaFX Gaussian Blur Effect example”. Also, it displays the text with and without Gaussian Blur Effect.


Related Topics

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Inner Shadow

In the JavaFX application, in order to apply various Inner Shadow effect, we use this class. It has the ability to create the inner shadow of the given object. This...

4 minutes read.

JavaFX - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

4 minutes read.

JavaFX Translation

In the JavaFX application, in order to apply various Translate effect, we use this class. It has the ability to Translate the given object according to the specified parameter. All...

4 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX Menu

In the JavaFX application, in order to create a menu, menu items, and menu bar, Menu, MenuItem, and MenuBar class is used. The menu allows us to choose options among...

4 minutes read.

JavaFX Rotate Transition

In the JavaFX application, in order to generate the rotate transition, we have to apply rotation transition on any particular shape. It has the ability to rotate the shape along...

4 minutes read.

JavaFX Label

The UI Control Label in a JavaFX is used to display the simple text. To use Label in JavaFX application javafx.scene.control.The label class is used. We can place Labels on...

3 minutes read.

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 minutes read.

JavaFX Installation

In order to run JavaFX applications, we need to have eclipse and java installed on our machine. Prerequisite: Operating systemAny Operating system (Windows, Linux, Mac)Memory requirementNo minimum requirementDisk SpaceNo minimum requirementJDK versionJDK...

3 minutes read.

JavaFX Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX ScrollBar

In the JavaFX application, in order to scroll over a range of values, ScrollBar is used. It is used to view long page contents. In order to use ScrollBar in...

4 minutes read.

JavaFX Motion Blur

In the JavaFX application, in order to apply various Motion blur effect, we use Motion Blur class. It has the ability to apply the Motion blur effect on the given...

4 minutes read.

JavaFX Event Filters

In JavaFX, in order to handle the event which are created by any of the mouse action, keyboard action, rotate action, scroll action Event filters are used. The event filters...

3 minutes read.

JavaFX HyperLink

In the JavaFX application, in order to access and use webpages, hyperlinks are used. In HTML anchor tags are used in the same way in JavaFX hyperlinks are used. To...

4 minutes read.

JavaFX HBox

In the JavaFX application, in order to set HBox as a layout, the HBox class is used. The HBox layout allows us to arrange the components in one row. All...

3 minutes read.

JavaFX PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

4 minutes read.

JavaFX Shear

In the JavaFX application, in order to apply various shear effect, we use this class. It has the ability to shear the given object along the x or y axis....

3 minutes read.

JavaFX Path Transition

In the JavaFX application, in order to generate the path transition, we have to apply path transition on any particular shape. It has the ability to traverse the given shape...

3 minutes read.

JavaFX Button Styling

 In the JavaFX application, we can apply CSS styling to buttons in various ways. We can change the size of the button as well as border colour, text colour can...

3 minutes read.