×

JavaFX Blend

In the JavaFX application, in order to apply various blend effect, we use Blend class. It has the ability to blend the colors of the shape. All methods needed for this purpose are present in the javafx.scene.effect.Blend class.

Properties and corresponding methods to create Blend Effect :

1. mode       

This property is of BlendMode type. It is used to represent the mode according to which blending is applied and the setMode( BlendMode value ) method is used to set it.

2. topInput

This property is of Effect type. It is used to represent the top input required for performing the blend operation and the setTopInput( Effect value) method is used to set it.

3. bottonInput

This property is of object type. It is used to represent the bottom input required for performing the blend operation and the setBottomInput( Effect value ) method is used to set it.

4. Opacity   

This property is of double type. It is used to represent the opacity value for the blend operation and the setOpacity( double value ) method is used to set it.

JavaFX Effect – Blend

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


import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    Circle circle = new Circle(190,170,140);         
    circle.setFill(Color.LIMEGREEN);   
    Blend blend = new Blend();    
    ColorInput color = new ColorInput(70, 20, 160, 150, Color.RED);  
    blend.setTopInput(color);  
    blend.setMode(BlendMode.ADD);     
    circle.setEffect(blend);         
    Group root = new Group(circle);   
        
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Blend Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create Blend 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.effect.BlendMode, javafx.scene.image.Blend, 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 a circle and rectangle with two different color having the blend effect, a Group object is created which is then passed to the Scene class object.

The circle is created using the constructor having size parameter passed to it. The limegreen is filled in the circle. The blend constructor is created. Using color input constructor the red color with size parameter forms a rectangle which specifies the blend effect on a circle. The blend mode is set to add which adds the two color and form the new color as the blend effect.

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 Blend Effect example”. Also, it displays the circle and the rectangle with limegreen and red color and blend effect with yellow color.

JavaFX Effect – Blend

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.ColorInput;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    Rectangle rect=new Rectangle(); 
        rect.setX(20); 
        rect.setY(20);    
        rect.setWidth(100); 
        rect.setHeight(100); 
        rect.setFill(Color.LIMEGREEN);
    Blend blend = new Blend();    
    ColorInput color = new ColorInput(70, 20, 160, 150, Color.RED);  
    blend.setTopInput(color);  
    blend.setMode(BlendMode.DARKEN);     
    rect.setEffect(blend);         
    Group root = new Group(rect);   
        
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Blend Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create Darken Blend 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.effect.BlendMode, javafx.scene.image.Blend, 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 rectangle with two different color having the darken blend effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created using the constructor having size parameter passed to it. The limegreen is filled in the rectangle. The blend constructor is created. Using color input constructor the red color with size parameter forms a rectangle and blend effect set to darken produces darken color as a blend effect.

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 Blend Effect example”. Also, it displays two rectangle with limegreen and red color respectively and darken blend effect with black color.

JavaFX Effect – Blend

Related Topics

JavaFX Line

In the JavaFX application, in order to draw a line, the Line class is used. The line allows us to join any two points with x and y coordinates in...

3 minutes read.

JavaFX Gradient Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the gradient colors in these shapes using the...

7 minutes read.

JavaFX Transformation

In the JavaFX application, in order to apply various transformation effects, we use Transform class. It has the ability to create the transformation on the given object. This transformation changes...

3 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 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 Fill Transition

In the JavaFX application, in order to generate the fill transition, we have to apply fill transition on any particular shape. It has the ability to fill the given shape...

4 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX TextField

In the JavaFX application, to get the user information as input from the user, a form is created using textfields which allows the user to enter input for specific fields....

4 minutes read.

JavaFX Light Point

In the JavaFX application, in order to apply various LightPoint effect from a single source, we use this class. It has the ability to apply light from a single source...

4 minutes read.

JavaFX Color Adjust

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

5 minutes read.

JavaFX Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 minutes read.

JavaFX Path Transition

In the JavaFX application, in order to generate the path transition, we have to apply path transition on any particular shape. It has the ability to traverse the given shape...

3 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 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 Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 minutes read.

JavaFX Motion Blur

In the JavaFX application, in order to apply various Motion blur effect, we use Motion Blur class. It has the ability to apply the Motion blur effect on the 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.