×

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 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 Fade Transition

In the JavaFX application, in order to generate the fade transition, we have to apply fade transition on any particular shape. It has the ability to show the fading colors...

4 minutes read.

JavaFX BorderPane

In the JavaFX application, in order to set Border Pane as a layout, the BorderPane class is used. The BorderPane layout allows us to arrange the components in the left,...

4 minutes read.

JavaFX Circle

In the JavaFX application, in order to draw a circle, the Circle class is used. The Circle allows us to join any points in the space. All methods needed for...

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 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 Bubble Chart

In the JavaFX application, in order to create Bubble Chart, the BubbleChart class is used. The Bubble Chart allows us to plot three dimensional data. All methods needed for this...

4 minutes read.

JavaFX ProgressBar

In the JavaFX application, in order to show the progress of work ProgressBar is used. It shows how much work is done. In order to use ProgressBar in JavaFX, javafx.scene.control.ProgressBar...

4 minutes read.

JavaFX Lighting

In the JavaFX application, in order to apply various Lighting effect from a single source, we use this class. It has the ability to lighten a node from a given...

4 minutes read.

JavaFX Sequential Transition

In the JavaFX application, in order to generate the sequential transition, we have to apply sequential transition on any particular shape. It has the ability to execute multiple transactions sequentially...

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 Selectors

In the JavaFX application, in order to apply various css effect, we use the various css classes available in the JavaFX. This is generally used to enhance the appearance property...

4 minutes read.

JavaFX Scaling

In the JavaFX application, in order to apply various Scaling effects, we use this class. It has the ability to change the size of the given object. All methods needed...

5 minutes read.

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 Arc

In the JavaFX application, in order to draw an arc, the Arc class is used. The Arc allows us to join any points in the space. All methods needed for...

5 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 Button

The button is one of the UI control present in the JavaFX. The javafx.scene.control.Button class is used for creating a button in javafx example. It is also possible to create...

5 minutes read.

JavaFX Tutorial

Introduction of JavaFX: The most popular applications called Rich Internet Application are build using the JavaFX. This application can run across many platforms. Various devices such as mobile, computers, and tablets...

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