Hello , Today I’m going to show the small demo of masking. In javafx masking is known as clipping. Every Node Object has
1 |
public final void <strong>setClip</strong>(<a title="class in javafx.scene">Node</a> 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):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Detective Glass"); Group root = new Group(); Scene scene = new Scene(root, 800, 470,Color.BLACK); //ImageView ImageView maskView = new ImageView(); maskView.setCursor(Cursor.NONE); //Image is loaded Image image = new Image(DetectiveGlass.class.getResource("oldimg.jpg").toExternalForm()); maskView.setImage(image); //Mask Shape final Circle glass = new Circle(100,100,100); maskView.setClip(glass); //adding to the root's children root.getChildren().add(maskView); //MouseMoved Event on Scene scene.setOnMouseMoved(new EventHandler(){ public void handle(MouseEvent event) { //Setting X and Y position of mask shape glass.setCenterX(event.getX()); glass.setCenterY(event.getY()); } }); primaryStage.setScene(scene); primaryStage.setVisible(true); } } |
A worked out example : Detective Glass
Feel free to comment.
Have a 🙂 good day.
Hi Narayan. Nice example.
Thank you for sharing.
Hi,
thanks for your nice example
Hi
i’m not sure this is a place to make my request but i hope someone will help me
i’m tring for severals day now to convert this javafx1.3 code to javafx 2.0
http://blogs.oracle.com/rakeshmenonp/entry/javafx_image_viewer
can someone please help me to convert it?
thanks
I think Javafx 2.0 is easy and flexible who have already knowledge of Java. So There won’t be any difficulties on converting 1.3 app to 2.0
you need Windows Mobile 6.0 or 6.1 platform installed on a target device with network connectivity, 32-bit RISC based microprocessor, and minimum 64 MB RAM.
1) First, you copy the SUN_JAVAFX.CAB file over to the device emulator file system
2) Click on the SUN_JAVAFX.CAB to install it
3) Copy the JavaFX application jar file over to the device emulator file system
4) Click on the jar file – this should start the JavaFX application installer and should ask you if you want to install the application
5) Once the installation finishes you can start JavaFX by choosing the “JavaFX” icon in the “Programs” section of the device
6) You should see your JavaFX application in the list of installed applications. Click to run it. Tesla Secret
What is this??
I just want to leave you an quick post to thank you for your blog! Keep up the good work! Much Thanks!
Perhaps this is one of the most interesting blogs that I have ever seen. Interesting article.
wonderful post, thank you.
Thanks for sharing Masking in Javafx 2.0 Java and FX with us keep update bro love your article about Masking in Javafx 2.0 Java and FX .
thanks for sharing the info.that is interesting.
Favorite post having such an fantastic and useful informative content. describing good blogging concepts as well as basics that are very much useful in skilled content writing as well
I think i got it, i just have to test it. Thanks a lot!
Hey! I just wish to give an enormous thumbs up for the great
information you’ve got right here on this post.
I might be coming again to your blog for more soon.
I just wish to give an enormous thumbs up for the great
information you’ve got thanks a lot dude!
Is there a way to create masking with complex shapes? What I have is an image of the back side of an iphone device and I’d like to create a “skin” for it using a photo but leaving the Apple logo as is (meaning not covered). Is there a way to achieve this if javaFX?
Thank you
@Stefanos,);
You can easily make use of “clipProperty” available for every Node . To make masking for the apple logo you need to make ImageView instance which will be shown to the user masking in the shape of applet logo.
imageToDisplay.setClip(
Thanks