Skip to content Skip to sidebar Skip to footer

Bind The Progress Of A Query To A Progressproperty Of A Progressbar For Informing The User Of Download And Upload Time In Javafx?

I got an app that upload and download images to a mysql database but this take like 5 secs and i want to tell the user the progress of this i do the transactions in a task here is

Solution 1:

Normally this is as simple as loading the image from a url in the background and tracking it's progress by binding the progress property of the progress bar to the progress property of the image. That would replicate the functionality of the Android code you posted with much less code.

ProgressBarbar=newProgressBar();
Imageimage=newImage(url, true);
bar.progressProperty().bind(image.progressProperty());

The only tricky thing here is that the non-Android code you posted is not the same as the Android code in functionality. Instead of retrieving an image from a URL, the non-Android code is retrieving the image from a database.

If you want to monitor progress of retrieval of images stored in a database, then you need to do a few extra things:

  1. In an additional field in the database store the size of the image.
  2. Store the image itself in a Blob in the database.
  3. Retrieve the total size of the image from the database when required.
  4. Retrieve the Blob from the database as a stream.
  5. Register a custom URL protocol which is able to get the database stream and convert the stream to a URL. (Alternately you could host a web application servlet which does the conversion and returns the data over http).
  6. Now you can load the image in the background using your custom URL protocol and monitor its progress via its progress property as before.

Doing step 5 is tricky and I will not write the code to do it here as creating such code would take me a long time.

Post a Comment for "Bind The Progress Of A Query To A Progressproperty Of A Progressbar For Informing The User Of Download And Upload Time In Javafx?"