×

JavaFX Bloom

In the JavaFX application, in order to apply various bloom effect, we use the Bloom class. It has the ability to bloom the colors of the shape. All methods needed for this purpose are present in the javafx.scene.effect.Bloom class.

Properties and corresponding methods to create Bloom Effect :

1. input

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

2. threshold

This property is of double type. It is used to represent the minimum value for glowness and the setThreshold( Double value) method is used to set it.

JavaFX Effect – Bloom

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;
import javafx.scene.effect.Bloom;
import javafx.scene.effect.ColorInput;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    Rectangle rect1= new Rectangle(60,50,200,200);  
        Rectangle rect2 = new Rectangle(325,50,200,200);  
        rect1.setFill(Color.BROWN);  
        rect1.setStroke(Color.BLACK);  
        rect1.setStrokeWidth(5);  
        rect2.setFill(Color.BROWN);  
        rect2.setStroke(Color.BLACK);  
        rect2.setStrokeWidth(5);  
        Text text1 = new Text();  
        Text text2 = new Text();  
        text1.setText(" Shape with Bloom Effect ");  
        text2.setText(" Shape without Bloom Effect ");  
        text1.setX(65);  
        text1.setY(300);  
        text2.setX(335);  
        text2.setY(300);  
     
        text1.setFill(Color.RED);  
        text2.setFill(Color.RED);  
        text1.setStroke(Color.BLACK);  
        text2.setStroke(Color.BLACK);  
        text1.setStrokeWidth(0.2);  
        text2.setStrokeWidth(0.2);  
        Bloom bloom = new Bloom();  
        bloom.setThreshold(0.1);  
        rect1.setEffect(bloom);  
        Group root = new Group();  
        root.getChildren().addAll(rect1,rect2,text1,text2);  
        Scene scene = new Scene(root,600,500);  
         stage.setScene(scene);  
        stage.setTitle(" JavaFx Bloom Effect example ");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create Bloom 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.ColorInput, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, javafx.scene.image.Bloom, 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 two rectangles with and without bloom effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor having the size parameter passed to it. The color, brown is filled in both the rectangle then the bloom constructor is created and it is applied to the first rectangle.

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 Bloom Effect example”. Also, it displays the two rectangle with and without bloom effect.

JavaFX Effect – Bloom

JavaFX Effect – Blend Darken mode Example :

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;
import javafx.scene.effect.Blend;
import javafx.scene.effect.BlendMode;
import javafx.scene.effect.Bloom;
import javafx.scene.effect.ColorInput;


import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;  


public class SliderUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    Circle circle1 = new Circle(120,120,60);         
    circle1.setFill(Color.LIMEGREEN);   
    Circle circle2 = new Circle(360,120,60);         
    circle2.setFill(Color.LIMEGREEN);   
        Text text1 = new Text();  
        Text text2 = new Text();  
        text1.setText(" Shape with Bloom Effect ");  
        text2.setText(" Shape without Bloom Effect ");  
        text1.setX(45);  
        text1.setY(200);  
        text2.setX(295);  
        text2.setY(200);  
     
        text1.setFill(Color.RED);  
        text2.setFill(Color.RED);  
        text1.setStroke(Color.BLACK);  
        text2.setStroke(Color.BLACK);  
        text1.setStrokeWidth(0.2);  
        text2.setStrokeWidth(0.2);  
        Bloom bloom = new Bloom();  
        bloom.setThreshold(0.1);  
        circle1.setEffect(bloom);  
        Group root = new Group();  
        root.getChildren().addAll(circle1,circle2,text1,text2);  
        Scene scene = new Scene(root,600,500);  
         stage.setScene(scene);  
        stage.setTitle(" JavaFx Bloom Effect example ");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create Bloom Effect on circle in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.effect.ColorInput, javafx.scene.paint.Color, javafx.scene.shape.Circle, javafx.scene.image.Bloom, 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 two circles with and without bloom effect, a Group object is created which is then passed to the Scene class object.

The circle is created with the help of the constructor having the size parameter passed to it. The color, limegreen is filled in both the circle then the bloom constructor is created and it is applied to the first circle.

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 Bloom Effect example”. Also, it displays the two circle with and without bloom effect.

JavaFX Effect – Bloom

Related Topics

JavaFX Convenience Methods

The JavaFX allows us to use various convenience methods to handle events on various nodes in JavaFX applications. The convenience methods provides us easy and effective way to add any...

4 minutes read.

JavaFX GridPane

In the JavaFX application, in order to set Grid Pane as a layout, the GridPane class is used. The GridPane layout allows us to arrange the components in the form...

4 minutes read.

JavaFX Sphere

In the JavaFX application, in order to draw a Sphere, the Sphere class is used. The Sphere allows us to form a 3D shape having circular faces. All methods needed...

4 minutes read.

JavaFX TextField

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

4 minutes read.

JavaFX Shadow

In the JavaFX application, in order to apply various Shadow effect from a single source, we use this class. It has the ability to create the shadow of the given...

3 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 Blend

In the JavaFX application, in order to apply various blend effect, we use Blend class. It has the ability to blend the colors of the shape. All methods needed for...

4 minutes read.

JavaFX Reflection

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

4 minutes read.

JavaFX ID selector

In the JavaFX application, in order to apply various css effect using the id selector, we use the various css classes available in the JavaFX. This is generally used to...

4 minutes read.

JavaFX Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.

JavaFX Bloom

In the JavaFX application, in order to apply various bloom effect, we use the Bloom class. It has the ability to bloom the colors of the shape. All methods needed...

4 minutes read.

JavaFX Box

In the JavaFX application, in order to draw a Box, the Box class is used. The Box allows us to form 3D shape having rectangular faces. All methods needed for...

4 minutes read.

JavaFX Scale Transition

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

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 Event Handling

JavaFX gives way to handle various events in web application, desktop applications and graphical applications. In the JavaFX application, in order to allow user to interact with application various events...

4 minutes read.

JavaFX Layouts

Layouts in the JavaFX application are treated as a container for different UI elements such as Button, Label, TextArea, etc. Layouts are used as parent container. The layout is used...

3 minutes read.

JavaFX Inline Styles

In the JavaFX application, in order to apply various Inline css effect we will use the various css classes available in the JavaFX. It is used to apply the various...

4 minutes read.

JavaFX Ellipse

In the JavaFX application, in order to draw an Ellipse, the Ellipse class is used. The Ellipse allows us to join any points in the space to draw the unique...

7 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 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.