简体   繁体   中英

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());
            }

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM