Will A
Will A

Reputation: 55

Taking a snapshot/screenshot of a certain portion of a screen (javaFX)

I want to be able to take a screenshot of a certain part of a scene in javaFX. Here is an image of what the scene looks like. I want to enter parameters (such as the size of the area and where the area will be) that mean that only the graph is screenshotted/snpashotted. However the graph itself is made up of labels and images. When it is screenshotted, I would like to save the screenshot, by either a WritableImage or copying it to clipboard, whichever is easier. How would I do this? If you need to know, I am using scene builder.

Upvotes: 0

Views: 1031

Answers (1)

MMAdams
MMAdams

Reputation: 1498

So long as your whole 'graph', including all its labels and such, is a javafx.scene.Node, you can use the snapshot function.

If they aren't already in the same node, consider adding them all as children of a Group, Parent or Region.

The way to do this in Scene Builder is to go into Miscellaneous, add a 'Group' or 'Region' and in the Document Hierarchy drag every label and node you want screenshotted into that group. You could also use anything under 'Containers' but those have other formatting to them that Group doesn't really have. Give the Group an fx:id and in your java code call snapshot on the Group. It's literally that easy.

Upvotes: 1

Related Questions