Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaFX ImageView Not Behaving

 
Michael D Sims
Ranch Hand
Posts: 70
1
Chrome Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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

Slides.xml

 
John Damien Smith
Ranch Hand
Posts: 299
14
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic