Home » Java » Desktop Java » JavaFX 2: How to Load Image

About Zoran Pavlovic

JavaFX 2: How to Load Image

This is JavaFX tutorial about how to load a image in your JavaFX 2 application. This can be done easily with ImageView. The ImageView is a Node used for painting images loaded with Image class. So as you can se we will first load image with Image class and then display it with ImageView. Also I will here demonstrate how to load image from local disk, and how to load image from Internet. First example is how to load an image from disk, then I’ll show how to modify it, to load image from Internet.

Load Image with ImageView in JavaFX 2

Load Image with ImageView in JavaFX 2

    import javafx.application.Application;
    import javafx.scene.Scene;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.layout.StackPane;
    import javafx.stage.Stage;
    * @author zoranpavlovic.blogspot.com
    public class LoadImage extends Application {
            * @param args the command line arguments
            public static void main(String[] args) {
            public void start(Stage primaryStage) {
            primaryStage.setTitle("Load Image");

            StackPane sp = new StackPane();
            Image img = new Image("javafx.jpg");
            ImageView imgView = new ImageView(img);

            //Adding HBox to the scene
            Scene scene = new Scene(sp);

Okay, what if you want to load a image from some Internet location? Well, that can be also easily done, just modify this line of code. The result will be same.

    Image img = new Image("http://mikecann.co.uk/wp-content/uploads/2009/12/javafx_logo_color_1.jpg");


Reference: JavaFX 2: How to Load Image from our JCG partner Zoran Pavlovic at the Zoran Pavlovic blog blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

and many more ....



  1. What if I want to dynamically choose the file from filechooser and upload it in the imageview

  2. if you want show from specified file ,you can use

    Image me = new Image(” file://”+fileway.toString);

Leave a Reply

Your email address will not be published. Required fields are marked *


Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.