JavaFX Tutorial Index

JavaFX Tutorial JavaFX Installation JavaFX Application Structure JavaFX Architecture

JavaFX Applications Charts

JavaFX Bar Chart JavaFX Bubble Chart JavaFX Pie Chart JavaFX Scatter Chart JavaFX Area Chart JavaFX Line Chart

JavaFX 2D Shapes

JavaFX Arc JavaFX Circle JavaFX Ellipse JavaFX Line JavaFX Polygon JavaFX Rectangle JavaFX Color JavaFX Gradient Color

JavaFX 3D Shapes

JavaFX Box JavaFX Cylinder JavaFX Sphere

JavaFX Animations

JavaFX Rotate Transition JavaFX Translate Transition JavaFX Fade Transition JavaFX Fill Transition JavaFX Parallel Transition JavaFX Path Transition JavaFX Pause Transition JavaFX Scale Transition JavaFX Sequential Transition JavaFX Stroke Transition

JavaFX CSS

JavaFX ID Selector JavaFX Inline Styles JavaFX Selectors

JavaFX Effect

JavaFX Blend JavaFX Bloom JavaFX Color Adjust JavaFX Color Input JavaFX Drop Shadow JavaFX Gaussian Blur JavaFX Glow JavaFX Image Input JavaFX Inner Shadow JavaFX Light Distant JavaFX Light Point JavaFX Light Spot JavaFX Lighting JavaFX Motion Blur JavaFX Reflection JavaFX Shadow

JavaFX Layouts

JavaFX Layouts JavaFX BorderPane JavaFX GridPane JavaFX StackPane JavaFX HBox JavaFX TilePane

JavaFX Event Handling

JavaFX Event Handling JavaFX Event Filters JavaFX Convenience Methods

JavaFX Transformation

JavaFX Transformation JavaFX Scaling JavaFX Rotation JavaFX Translation JavaFX Shear

JavaFX UI

JavaFX Menu JavaFX Button JavaFX Button Styling JavaFX CheckBox JavaFX File Chooser JavaFX HyperLink JavaFX Label JavaFX UI Controls JavaFX PasswordField JavaFX ProgressBar JavaFX RadioButton JavaFX ScrollBar JavaFX Slider JavaFX TextField

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