5 Replies Latest reply on Sep 19, 2013 5:50 PM by jsmith

    Snapshot of any node throws IllegalArgumentException when screen is locked - how can we avoid this?


      Here's some example code that won't work if the snapshot is taken while the screen is locked (and it was locked after application start) in both Java 7 and 8.

      Is there a way to test whether the screen is locked or even better get notified when it is unlocked, so we don't accidentally run into this?

      I also suspect there are more causes than just the screen being locked, so it would be great to know when this can happen in general.


      import javafx.application.Application;

      import javafx.application.Platform;

      import javafx.scene.Scene;

      import javafx.scene.layout.BorderPane;

      import javafx.scene.paint.Color;

      import javafx.scene.shape.Rectangle;

      import javafx.stage.Stage;


      public class SnapshotTester extends Application {



          public void start(Stage primaryStage) throws Exception {


              final BorderPane borderPane = new BorderPane();

              final Rectangle rectangle = new Rectangle(20, 20, Color.BLUE);


              Scene scene = new Scene(borderPane);




              new Thread(new Runnable() {


                  public void run() {

                      try {


                          Platform.runLater(new Runnable() {


                              public void run() {

                                  Image snapshot = rectangle.snapshot(null, null);

                                  System.out.println("Snapshot taken: " + snapshot);



                      } catch (InterruptedException ignored) {






          public static void main(String[] args) {






      To reproduce do the following:

      1) Start application

      2) Lock screen as soon as window is shown

      3) Unlock after two seconds

      You'll get the following exception which is unfortunately not very expressive:

      java.lang.IllegalArgumentException: Unrecognized image loader: null
      at javafx.scene.image.WritableImage.loadTkImage(WritableImage.java:230)
      at javafx.scene.image.WritableImage.access$000(WritableImage.java:44)
      at javafx.scene.image.WritableImage$1.loadTkImage(WritableImage.java:49)
      at javafx.scene.Scene.doSnapshot(Scene.java:1144)
      at javafx.scene.Node.doSnapshot(Node.java:1632)
      at javafx.scene.Node.snapshot(Node.java:1710)