• 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JavaFX ImageView Not Behaving

 
Ranch Hand
Posts: 167
1
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
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

 
Rancher
Posts: 387
30
  • 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.
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic