jQuery in Action, 2nd edition*
The moose likes JavaFX and the fly likes Not sure why ImageView is empty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Not sure why ImageView is empty" Watch "Not sure why ImageView is empty" New topic
Author

Not sure why ImageView is empty

Jacob Morehouse
Greenhorn

Joined: Feb 22, 2012
Posts: 17
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

Joined: Jan 26, 2012
Posts: 130
    
    9
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

Joined: Jan 26, 2012
Posts: 130
    
    9
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

Joined: Feb 22, 2012
Posts: 17
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not sure why ImageView is empty
 
Similar Threads
JavaFX never free memory
How do I remove a node?
Three questions about images
Insider's Guide to Mixing Swing and JavaFX
JavaFX 2.0 - Input Window (display driver crash)