Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

JavaFX ImageView Not Behaving

Ranch Hand
Posts: 167
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I wanted a small program that would simply iterate through a chosen folder down through subfolders building a list of images and then displaying them for a short period of time ... a slideshow ... So far so good, but I seem to be having issues with making the images full screen and resized (sized down if they are bigger than the screen or sized up if too small) so that they fill the whole screen (maintaining aspect ratio of course).

There seems to be one more issue as well ... when the list of files is particularly large (over 50), after it displays a number of files, it errors out and says it ran out of memory... so I’m obviously not cleaning up between pics and I’m not sure how to do that.

Here is the code ... where have I gone wrong?

Here is the FXML file


Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are calling Thread.sleep on the JavaFX application thread => never do that, it will just freeze up your application and make it unresponsive.

Perhaps use a PauseTransition instead (a pause transition gives control back to the JavaFX system while the pause is occurring).

You are loading into memory the entire decoded image data for all of the files in a folder at the same time. You don't need to do that. Instead load one file, run a pause transition. For example, when the pause transition completes in it's setOnFinished event handler, load the next file and do another pause transition.

Also don't use System.exit(0) calls to quit your application, instead let the application end naturally rather than forcing through System.exit. If you must force an exit of a JavaFX application, use Platform.exit either instead of or as well as System.exit. If you do call System.exit to exit for an fatal error condition, then have it return a non-zero value. InterruptedExceptions are normal you don't need exit the system when you get an interrupt, you can restore the interrupt status instead (Thread.currentThread().interrupt();) - though when you remove your Thread.sleep calls you won't have a possibility of interrupts so you won't need to handle them.
Fire me boy! Cool, soothing, shameless self promotion:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic