Forum Stats

  • 3,827,608 Users
  • 2,260,798 Discussions


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

Andipa Member Posts: 25
edited Sep 19, 2013 1:50PM in JavaFX 2.0 and Later

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(
at javafx.scene.image.WritableImage.access$000(
at javafx.scene.image.WritableImage$1.loadTkImage(
at javafx.scene.Scene.doSnapshot(
at javafx.scene.Node.doSnapshot(
at javafx.scene.Node.snapshot(



This discussion has been closed.