0

I have a GIF image file that I was displaying in an ImageView with JavaFX. I am allowing administrators to change the logo file and I want to ensure it scales correctly to fit the display area. I had it all working until I had a file that was a bit taller than wide and taller than the fitHeight.

When the file is not a happy size, the image does NOT display. I'd like some suggestions for a fall-back strategy. My preferred options are:

  • Detect if the image will fail-to-display after the ImageView.setImage() method
    • I can then reload the image and change the fitHeight to a known safe value and issue a warning, or
  • Force the image to display so that it is clipped to the fitWidth and fitHeight
  • Keep the previous image if the file is incompatible
    • Reuse the previous image by saving: this.logo.getImage()
    • Trick question: How do I know the image does not display / will be incompatible?
  • I wondered if there's an event that I can check to verify/fix an image load?

I'm open to alternative strategy suggestions. For a bit of context the logo image is specified by a URL via a config file and an FXML that is loaded at (unattended) boot time. We can't have a blank box on-screen something needs to be done if there's a problem displaying an image.

I can't identify a JavaFX call to inform me if the image is actually visible after the setImage() call. To be fair the scene refresh happens after this.

I have identified the source of the The following the top line works:

 <ImageView fx:id="logo" fitHeight="320.0" fitWidth="600.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="CENTER" GridPane.valignment="CENTER">

This version fails to display:

 <ImageView fx:id="logo" fitHeight="360.0" fitWidth="600.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="CENTER" GridPane.valignment="CENTER"> 

fitHeight values under about 350 work, determined by experimentation. When fitHeight is too high, the image is invisible (not displayed).

possibly related:

Community
  • 1
  • 1
will
  • 4,799
  • 8
  • 54
  • 90
  • Perhaps this will be useful: (Using various properties of `Image` itself): http://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/Image.html – Forager Aug 08 '14 at 15:30
  • @Forager, yes I looked at the image -- Actually that _is_ the question. How can I determine the Image attributes for the specific ImageView so that I can load the image such that it will be clipped, scrolled or resized depending on the use-case. I can do resize, but clipping doesn't seem to behave. Also the when it not clipped it can and does *vanish* -- so we need to know if the image has _vanished_ and take corrective action! – will Aug 09 '14 at 00:18
  • By image clipping, do you mean displaying as is, while cutting off anything that goes off-window, or do you mean resizing the image? I can't say I fully understand what's causing your issue, but it seems like you understand it to be a problem with image size. Is the `isError()` method not applicable for your case? – Forager Aug 09 '14 at 01:50
  • This is a FXML scene using Java JavaFX 2. The question is about the ImageView JavaFX control, not the Image object. The image object is perfectly "_fine_". Even if it worked (and it doesn't) isError would not tell me IF something displayed, hidden or had been clipped, scroll/overflow or chopped. – will Aug 09 '14 at 11:43

0 Answers0