Bloom Class
The Bloom class is a component of JavaFX. Bloom is a creative effect that, in accordance with a programmable threshold, causes brighter areas of the input image to appear to glow. The javafx.scene.effect package is inherited by the Bloom class.
Properties
The Bloom class contains two properties:
-
Input: This attribute, which belongs to the Effect class, is an input for the bloom effect. The setInput(Effect value) is used to set it.
- Threshold: The threshold value of brightness for the node's pixels is represented by this attribute, which is of the double type. Each pixel with luminance greater than or equal to this value gets illuminated. The threshold value's range is 0.0 to 1.0. The setThreshold(Double value) is used to set it.
Constructors
Bloom(): The Bloom() constructor generates a new Bloom Object.
Bloom(double th): This constructor adds a new instance of the Bloom effect with the given threshold.
Syntax
The Syntax for creating the bloom effect:
Bloom blm = new Bloom()
A Bloom object is created using the no-args constructor with a default threshold of 0.30. You can define the threshold value with the other constructor.
Methods
Let’s discuss some commonly used methods of the Bloom effect class in JavaFX.
- getInput(): It obtains the value of the input property.
- getThreshold(): It returns the threshold value that was set.
- Input (Effect e): It sets the value of the input set property.
- Threshold (double th): It sets the effect's threshold value.
Sample Example
We will see the example of the Bloom effect in JavaFX for your better grasp of the bloom effect. Before that let’s understand the steps of applying the bloom effect.
Steps to Apply Bloom Effect
Step 1: First of all, we need to import all the required libraries. Such as:
- javafx.application.Application
- javafx.scene.Group
- javafx.scene.Scene
- javafx.scene.image.Bloom
-
javafx.stage.Stage and many more as per your requirement.
Step 2: Create one class extending the Application Class. In order to provide implementation details, we also need to override the start method. This function generates a primaryStage object from a Stage object.
Step 3: Create an instance of the Bloom effect class which should be applied.
Step 4: Now set the properties of the bloom effect.
Step 5: Use the instance object to call the setEffect() function and pass the Bloom effect class object as an argument to that function.
Example
Here is one example of the Bloom Effect in JavaFX.
Code
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Bloom;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class Bloom_Example1 extends Application {
@Override
public void start(Stage stage) {
//Creating a Text object
Text text = new Text();
//Setting font to the text
text.setFont(Font.font(null, FontWeight.BOLD, 40));
//setting the position of the text
text.setX(150);
text.setY(200);
//Setting the text to be embedded.
text.setText("Hey Ninja! Welcome!!");
//Setting the colour to the text
text.setFill(Color.PURPLE);
//Instantiating the shape named Rectangle class
Rectangle shape = new Rectangle();
//Setting the position of our rectangle
shape.setX(60.0f);
shape.setY(80.0f);
//Setting the width of rectangle
shape.setWidth(500.0f);
//Setting the height of rectangle
shape.setHeight(150.0f);
//Setting the color of the rectangle
shape.setFill(Color.GOLDENROD);
//Instantiating the Bloom class
Bloom blm = new Bloom();
//setting threshold for bloom
blm.setThreshold(0.1);
//Applying bloom effect to text
text.setEffect(blm);
//Creating a Group object
Group root = new Group(shape, text);
//Creating a scene object
Scene scene = new Scene(root, 600, 300);
//Setting title to the Stage
stage.setTitle("Coding_Ninjas " +
"Application");
//Adding scene to the stage
stage.setScene(scene);
//Displaying contents of the stage
stage.show();
}
public static void main(String args[]){
launch(args);
}
}
Output

Frequently Asked Questions
How many life cycle stages are there in the JavaFX application?
The life cycle of a JavaFX application has three stages.
Does JavaFX run in browsers?
The Deployment Toolkit library is suggested for usage when launching a JavaFX application from a web page or embedding one there. The JavaScript API offered by the Deployment Toolkit makes it easier to deploy JavaFX applications on the web and enhances the user experience when the program launches.
Is JavaFX preferable to Swing?
Both approaches have a lot to offer Java developers who want to create plug-in UI components. Swing might provide developers an advantage with its extensive collection of UI components, but JavaFX can beat Swing when it comes to creating trendy, rich online applications.
Conclusion
In this blog, we ran through the Bloom effect in JavaFX. We discussed the Properties, Constructors, and Methods of the Bloom effect. We have also discussed sample example to understand the working of the Bloom effect in JavaFX.
We hope this blog increased your knowledge regarding the bloom effect in JavaFX. We recommend you to visit our articles on different topics of JavaFX, such as
If you liked our article, do upvote our article and help other ninjas grow. You can refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, System Design, and many more!
Head over to our practice platform Coding Ninjas Studio to practice top problems, attempt mock tests, read interview experiences, interview bundle, follow guided paths for placement preparations, and much more!!
We wish you Good Luck! Keep coding and keep reading Ninja!!