JavaFX | Glow Class
Glow class is a part of JavaFX. Glow is a high-level effect that makes the input image appear to glow using a configurable threshold. Glow class inherits Effect class.
Constructors of the class:
- Glow(): Creates a new glow object with default parameters.
- Glow(double l): Creates a new instance of Glow with specified level.
Commonly Used Methods:
| Method | Explanation |
|---|---|
| getInput() | Returns the value of property input |
| setInput(Effect v) | Sets the value of property input |
| setLevel(double v) | Set the value of level of glow object |
| getLevel() | Returns the value of level of glow object |
Below programs illustrate the use of the Glow class:
- Java Program to add a image and add Glow effect to it: In this program a FileInputStream is created and an image is taken as input from a file. Image named image is created using the input from the file input stream. From the image, an image view object is created and it is added to the VBox. The VBox is then added to the scene and the scene is added to the stage. A Glow effect is created with a specified level passed as parameters and the effect is set to the image view using setEffect() function.
// Java Program to add a image and// add Glow effect to it.importjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.image.*;importjavafx.scene.effect.*;importjava.io.*;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.Group;publicclassglow_1extendsApplication {// launch the applicationpublicvoidstart(Stage stage)throwsException{// set title for the stagestage.setTitle("Glow Example");// create a input streamFileInputStream input =newFileInputStream("D:\\GFG.png");// create a imageImage image =newImage(input);// create a image ViewImageView imageview =newImageView(image);// create a glow effectGlow glow =newGlow(0.5);// set effectimageview.setEffect(glow);// create a VBoxVBox vbox =newVBox(imageview);// create a sceneScene scene =newScene(vbox,200,200);// set the scenestage.setScene(scene);stage.show();}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}chevron_rightfilter_noneInput Image:
Output:
- Java Program to add an image and add a Glow effect to it, and also add a button to change the glow level: In this program, an FileInputStream is created and an image is taken as input from a file. Image named image is created using the input from the file input stream. From the image, an image view object is created and it is added to the VBox. The VBox is then added to the scene and the scene is added to the stage. A Glow effect is created with a specified level passed as parameters and the effect is set to the image view using setEffect() function. A Button named button is created which is used to increase the glow of the image. The button is also added to the VBox. The glow of the image is increased using the setLevel() function. The events related to the button is handled using EventHandler.
// Java Program to add a image and// add Glow effect to it, and also// add a button to change the glow levelimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.image.*;importjavafx.scene.effect.*;importjava.io.*;importjavafx.event.ActionEvent;importjavafx.event.EventHandler;importjavafx.scene.Group;publicclassglow_2extendsApplication {doublelevel =0.1;// launch the applicationpublicvoidstart(Stage stage)throwsException{// set title for the stagestage.setTitle("Glow Example");// create a input streamFileInputStream input =newFileInputStream("D:\\GFG.png");// create a imageImage image =newImage(input);// create a image ViewImageView imageview =newImageView(image);// create a glow effectGlow glow =newGlow(level);// create a buttonButton button =newButton("Glow");// action eventEventHandler<ActionEvent> event =newEventHandler<ActionEvent>() {publicvoidhandle(ActionEvent e){// increase the levellevel +=0.1;if(level >1)level =0.0;// set Level gor glowglow.setLevel(level);}};// set on action of buttonbutton.setOnAction(event);// set effectimageview.setEffect(glow);// create a VBoxVBox vbox =newVBox(imageview, button);// create a sceneScene scene =newScene(vbox,200,200);// set the scenestage.setScene(scene);stage.show();}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(args);}}chevron_rightfilter_noneInput Image:
Output Image:
Note: The above programs might not run in an online IDE. Please use an offline compiler.
Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/effect/Glow.html
Recommended Posts:
- JavaFX | Tab Class
- JavaFX | Pos Class
- JavaFX | VBox Class
- JavaFx | GaussianBlur Class
- JavaFX | BoxBlur Class
- JavaFX | Reflection Class
- JavaFX | HBox Class
- JavaFX | Pane Class
- JavaFX | AnchorPane Class
- JavaFX | BorderPane Class
- JavaFX | Canvas Class
- JavaFX | Group Class
- JavaFX | DropShadow Class
- JavaFX | TabPane Class
- JavaFX | Slider Class
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




