Newbie Coder
Newbie Coder

Reputation: 151

How to Lazy load images in JavaFx?

Is it possible to do a lazy loading for images in JavaFx? It has a hundreds of picture and it took time to load the images. I would like to implement lazy loading so when I am scrolling on the stackpane, the images will also load.

            File[] listOfFiles = folder.listFiles();

            for (int i = 0; i < listOfFiles.length; i++) {
                Image img = new Image(listOfFiles[i].toURI().toString());
            }

Upvotes: 3

Views: 480

Answers (1)

Raw
Raw

Reputation: 506

You can use background loading see in the documentation. With the flag true

Image myImage= new Image("/icons/test.png",true);

Upvotes: 1

Related Questions