Headless environment error in java.awt.Robot class with MAC OS
问题 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