Hello , Today I’m going to show the small demo of masking. In javafx masking is known as clipping. Every Node Object has

public final void setClip(Node value)

You can use the setClip to any Node.The setClip is used to mask for specific dimension of the existing Node.Let’s see the demo application of this masking in Detective Glass Application.

Source Code (DetectiveGlass.java):

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

 * @author Narayan G.M
public class DetectiveGlass extends Application {

    public static void main(String[] args) {
        Application.launch(DetectiveGlass.class, args);
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Detective Glass");
        Group root = new Group();
        Scene scene = new Scene(root, 800, 470,Color.BLACK);

        ImageView maskView = new ImageView();    
        //Image is loaded 
        Image image = new Image(DetectiveGlass.class.getResource("oldimg.jpg").toExternalForm());
        //Mask Shape 
        final Circle glass = new Circle(100,100,100);
        //adding to the root's children
        //MouseMoved Event on Scene
        scene.setOnMouseMoved(new EventHandler(){

            public void handle(MouseEvent event) {                
                //Setting X and Y position of mask shape


Detective Glass (Masking)

A worked out example : Detective Glass


Feel free to comment.

Have a 🙂 good day.