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 Image Input

In the JavaFX application, in order to apply various image input effect, we use the ImageInput class. It has the ability to fill the specified shape with a given image input effect. All methods needed for this purpose are present in the javafx.scene.effect.ImageInput class.

Properties and corresponding methods to create Image Input Effect :

1. x

This property is of double type. It is used to represent the x top left coordinate of the shape and the setX( double xvalue ) method is used to set it.

2. y

This property is of double type. It is used to represent the y top left coordinate of the shape and the setY( double yvalue) method is used to set it.

3. source

This property is of image type. It is used to represent the url of the specified image and the setImage( Image img ) method is used to set it.

JavaFX Effect – Image Input

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
      Image img = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");  
        ImageInput imginput = new ImageInput();  
        Rectangle rect = new Rectangle();  
        imginput.setSource(img);  
        imginput.setX(20);  
        imginput.setY(70);  
        Group root = new Group();  
        rect.setEffect(imginput);  
        root.getChildren().add(rect);  
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Image Input Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the image Input 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.ImageInput, javafx.scene.image.Image, 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 rectangle filled with image input effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor and Image input constructor is created, various properties are set using the setters, and the setEffect() method is used to set the image input effect on the rectangle.

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 Image Input Effect example". Also, it displays a rectangle with a home icon image input effect on it.

JavaFX Effect – Image Input

JavaFX Effect – Rectangles with and without Image Input Effect Example :

Example:

import javafx.application.Application;  
import javafx.scene.Group;  
import javafx.scene.Scene;  
import javafx.scene.effect.ImageInput;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.stage.Stage;  


public class EffectUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
      Image img = new Image("https://icons.iconarchive.com/icons/custom-icon-design/pretty-office-4/256/home-icon.png");  
        ImageInput imginput = new ImageInput();  
        Rectangle rect = new Rectangle();  
        Rectangle rect2 = new Rectangle();  
            rect2.setX(320);
            rect2.setY(90);;
        rect2.setHeight(240);  
          rect2.setWidth(240);  
          Text text1 = new Text();  
            Text text2 = new Text();  
            text1.setText("ImageInput Effect Applied");  
            text2.setText("ImageInput Effect Not Applied");  
            text1.setX(100);  
            text1.setY(350);  
            text2.setX(350);  
            text2.setY(350);  
            text1.setFill(Color.RED);  
            text2.setFill(Color.RED);  
            text1.setStroke(Color.BLACK);  
            text2.setStroke(Color.BLACK);  
            text1.setStrokeWidth(0.2);  
            text2.setStrokeWidth(0.2);  
       


        imginput.setSource(img);  
        imginput.setX(20);  
        imginput.setY(70);  
        Group root = new Group(rect,rect2,text1,text2);  
        rect.setEffect(imginput);  
        
         Scene scene = new Scene(root,700,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Image Input Effect example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the rectangle with and without image Input 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.ImageInput, javafx.scene.image.Image, 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 rectangle filled with and without image input effect, a Group object is created which is then passed to the Scene class object.

The rectangle is created with the help of the constructor and the Image input constructor is created, various properties are set using the setters and the setEffect() method is used to set the image input effect on one rectangle and other without 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 Image Input Effect example”. Also, it displays a rectangle with and without a home icon image input effect on it.

JavaFX Effect – Image Input