I am trying to capture screen shots in my JavaFX application using Robot class,
this is the code which I used in my application:
Rectangle screenBounds = new Rectangle(Screen.getPrimary().getBounds().getWidth(),
           Screen.getPrimary().getBounds().getHeight());
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(new java.awt.Rectangle(
     (int) screenBounds.getX(), (int) screenBounds.getY(), (int) 
             screenBounds.getWidth(), (int) screenBounds.getHeight()));
It is working perfectly in windows operating system, but showing an error of headless environment in MAC OS at Robot robot = new Robot();
This is to answer my own question, after searching many resources.
I have used following code to disable headless environment, and the problem is solved.
static {
        System.setProperty("java.awt.headless", "false");
}
Thanks.
From their API I can see the following:
So you need to check your hardware and their drivers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With