2

I want to be able to take a screenshot of a portion or all of the screen using Java. The generally accepted method of doing this to use the Robot class, but that doesn't work in this case. I have multiple transparent JavaFX stages on the screen, and any screenshot taken with the Robot class seems to treat them as completely opaque.

I have also tried having the program simulate the presses of Ctrl+PrtSc. I can't seem to get it to actually put the screenshot into the clipboard before the method finishes though, even if I attempt to have it wait until there is a picture in the clipboard.

Is there any more direct way of getting a screenshot? Anything specific to Swing/AWT, unfortunately, will not work.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Sharpevil
  • 194
  • 5
  • 18
  • 3
    Possible duplicate of [Is there a way to take a screenshot using Java and save it to some sort of image?](https://stackoverflow.com/q/58305/608639) and [How to take a screenshot in Java?](https://stackoverflow.com/q/4490454/608639) – jww Jul 26 '17 at 22:06
  • Both of these questions' answers suggest using the Robot class, which I've already said doesn't work in this case. – Sharpevil Jul 27 '17 at 02:42
  • Some of the answers avoid `Robot` class. For example, [this answer](https://stackoverflow.com/a/10796047/608639) says, *"I never liked using Robot, so I made my own simple method for making screenshots of JFrame object..."*. – jww Jul 27 '17 at 02:45
  • That answer is for JFrame windows. I've stated that I'm using JavaFX stages. Every other answer in both questions makes use of the Robot class. – Sharpevil Jul 27 '17 at 06:14

0 Answers0