JavaFX Glow
In the JavaFX application, in order to apply various glow effect, we use Glow class. It has the ability to glow the colors of the shape. All methods needed for this purpose are present in the javafx.scene.effect.Glow class.
Properties and corresponding methods to create Glow 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. level
This property is of double type. It is used to set the intensity of the color of the shape to which the Glow effect is applied and the setlevel( Double value) method is used to set it.
JavaFX Effect – Glow Effect on shape
Example:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.Glow;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class EffectUI extends Application {
@Override
public void start(Stage stage) throws Exception
{
Circle circle1 = new Circle(120,120,60);
circle1.setFill(Color.BLUE);
Circle circle2 = new Circle(360,120,60);
circle2.setFill(Color.BLUE);
Text text1 = new Text();
Text text2 = new Text();
text1.setText(" Shape with GLOW Effect ");
text2.setText(" Shape without GLOW 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);
Glow glow = new Glow();
glow.setLevel(10);
circle1.setEffect(glow);
Group root = new Group();
root.getChildren().addAll(circle1,circle2,text1,text2);
Scene scene = new Scene(root,600,500);
stage.setScene(scene);
stage.setTitle(" JavaFx Glow Effect example ");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Output:
In order to create Glow 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.Circle, javafx.scene.effect.Glow, 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 glow 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, blue is filled in both the circle then the glow 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 Glow Effect example”. Also, it displays the two circles with and without glow effect.
JavaFX Effect – Glow Effect on Image :
Example:
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.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class EffectUI extends Application {
@Override
public void start(Stage stage) throws Exception
{
Image img1 = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");
Image img2 = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");
ImageView imgview1 = new ImageView(img1);
ImageView imgview2 = new ImageView(img2);
imgview1.setX(30);
imgview1.setY(40);
imgview2.setX(300);
imgview2.setY(40);
Text text1 = new Text();
Text text2 = new Text();
text1.setText(" Image with GLOW Effect ");
text2.setText(" Image without GLOW Effect ");
text1.setX(65);
text1.setY(310);
text2.setX(345);
text2.setY(310);
text1.setFill(Color.RED);
text2.setFill(Color.RED);
text1.setStroke(Color.BLACK);
text2.setStroke(Color.BLACK);
text1.setStrokeWidth(0.2);
text2.setStrokeWidth(0.2);
Glow glow = new Glow();
glow.setLevel(10);
imgview1.setEffect(glow);
Group root = new Group();
root.getChildren().addAll(imgview1,imgview2,text1,text2);
Scene scene = new Scene(root,600,500);
stage.setScene(scene);
stage.setTitle(" JavaFx Glow Effect example ");
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Output:
In order to create Glow Effect on image 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.image.Image, javafx.scene.image.ImageView, javafx.scene.effect.Glow, 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 images with and without glow effect, a Group object is created which is then passed to the Scene class object.
The image is created with the help of the constructor having the size parameter passed to it. Then the glow constructor is created and it is applied to the first image.
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 Glow Effect example”. Also, it displays the two images with and without the glow effect