Kabir
Kabir

Reputation: 1489

File load completion check in java

I am working on a image browser project where I need to handle lots of image files. I have created a FlowPane and added those image files using a loop. But when it loads, it stuck for few seconds. I want to get rid of this.

I found that this problem relate with loading those files. My solution is to load all files in a synchronized way where files will load one at a time. How can I do that?

Is there any way to check if file loading and displaying complete?

Upvotes: 0

Views: 87

Answers (1)

Nikos Paraskevopoulos
Nikos Paraskevopoulos

Reputation: 40308

If you are loading the images in the main thread, then the UI freeze should be expected. You should load the images in a background process (i.e. one or more separate thread(s)). Before reading this, you can try loading the images (javafx.scene.image.Image) as:

Image x = new Image("file:///path/to/image.jpg", true);

...for background loading. See also the relevant property progress and method cancel() of Image.

Upvotes: 1

Related Questions