• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not sure why ImageView is empty

 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!


I'm a bit new to Java and JavaFX, so I'm sure this is an easy fix. First the context - I've written a program to list TIFF files and make them viewable in a little popup window. Here is the code for that window:


When the new stage appears it is completely empty. I've spent a bit of time on this and I think my problem lies in one of two places: I have specified the file path incorrectly (though this is the only variation that doesn't throw an exception), OR I have incorrectly formed the UI components and something isn't attaching to the scene/stage.

Even if someone can tell me definitively which of the two it is it would be a great help, then I'm only diving down one rabbit hole...

Thanks!
Jake
 
John Damien Smith
Ranch Hand
Posts: 287
13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your example seems fine to me.

A new stage will automatically size itself to it's content, so although it does no harm, you don't need the calls:

Check and see if there was an error loading the image:

You could place a \ at the beginning of the local image path, e.g. "\\C:\\ProgramFiles\\ImageViewer\\someTiff.tif", but it worked both with and without the leading \ for me. Note the double slashes \\ in the string constant to escape the \ character.

Here is a complete sample I used which worked for me:
 
John Damien Smith
Ranch Hand
Posts: 287
13
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah just realized, you are trying to load a TIFF file, which is not an image format which JavaFX understands.

There are a couple of threads around TIFF display here:
https://forums.oracle.com/forums/thread.jspa?threadID=2406945 "Display TIF image windows 7"
https://forums.oracle.com/forums/thread.jspa?threadID=2460597 "Multipage TIFFs"

Essentially you will need to use another library to load the TIFF, such as Java Advanced Imaging (JAI):
http://www.oracle.com/technetwork/java/javase/tech/jai-142803.html

And then you will need convert the loaded buffered image to a JavaFX image using SwingFXUtils.toFXImage so that your JavaFX program can display it:
http://docs.oracle.com/javafx/2/api/javafx/embed/swing/SwingFXUtils.html#toFXImage%28java.awt.image.BufferedImage,%20javafx.scene.image.WritableImage%29
 
Jacob Morehouse
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you John! I tried it so many different ways and never thought to change the file type. I tested with a .png and of course it worked perfectly.

Thank you so much for the detailed and thorough reply, very appreciated.


Jake

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic