JavaFX – Glow Effect


JavaFX – Glow Effect


”;


Just like the Bloom Effect, the Glow Effect also makes the given input image to glow. This effect makes the pixels of the input much brighter.

The class named Glow of the package javafx.scene.effect represents the glow effect. This class contains two properties namely −

  • input − This property is of the type Effect and it represents an input to the glow effect.

  • level − This property is of the type double; it represents intensity of the glow. The range of the level value is 0.0 to 1.0.

Example

The following program is an example demonstrating the Glow Effect of JavaFX. In here, we are embedding the following image (Tutorialspoint Logo) in JavaFX scene using Image and ImageView classes. This will be done at the position 100, 70 and with fit height and fit width 200 and 400 respectively.

Glow Effect

To this image, we are applying the Glow Effect with the level value 0.9. Save this code in a file with the name GlowEffectExample.java.

import javafx.application.Application; 
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.scene.effect.Glow; 
import javafx.scene.image.Image; 
import javafx.scene.image.ImageView; 
import javafx.stage.Stage; 
         
public class GlowEffectExample extends Application { 
   @Override 
   public void start(Stage stage) {               
      //Creating an image 
      Image image = new Image("http://www.tutorialspoint.com/green/images/logo.png");
   
      //Setting the image view 
      ImageView imageView = new ImageView(image); 
      
      //setting the fit width of the image view 
      imageView.setFitWidth(200);  
      
      //Setting the preserve ratio of the image view 
      imageView.setPreserveRatio(true);       
       
      //Instantiating the Glow class 
      Glow glow = new Glow(); 
      
      //setting level of the glow effect 
      glow.setLevel(0.9); 
      
      //Applying bloom effect to text 
      imageView.setEffect(glow);          
         
      //Creating a Group object  
      Group root = new Group(imageView);   
               
      //Creating a scene object 
      Scene scene = new Scene(root, 600, 300);  
      
      //Setting title to the Stage 
      stage.setTitle("Sample Application"); 
         
      //Adding scene to the stage 
      stage.setScene(scene); 
         
      //Displaying the contents of the stage 
      stage.show();         
   } 
   public static void main(String args[]){ 
      launch(args); 
   } 
}      

Compile and execute the saved java file from the command prompt using the following commands.

javac --module-path %PATH_TO_FX% --add-modules javafx.controls GlowEffectExample.java 
java --module-path %PATH_TO_FX% --add-modules javafx.controls GlowEffectExample

Output

On executing, the above program generates a JavaFX window as shown below.

Glow Effect Example

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *