1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Resolved How To Load An Image From Resources

Discussion in 'Developer Support' started by Stopper Blocker, May 13, 2016.

  1. Stopper Blocker

    Joined:
    Apr 19, 2016
    Messages:
    55
    Likes Received:
    17
    I have an imageView in a '.FXML' file and I want to provide it an image. Is there a way to do it manually, in SceneBuilder? If not, how would I do it using the Resources class? I have tried using the following but without luck:
    Code (Text):
    1. Resources.getAsBufferedImage(SOME_IMAGE_STR)
     
  2. Best Answer:
    Post #2 by Party, May 13, 2016
  3. Party

    Party Client Developer

    Joined:
    Oct 12, 2015
    Messages:
    3,708
    Likes Received:
    1,606
    @FXML
    private ImageView img;

    ....

    //In your initialise
    Image image = new Image(Resources.getAsStream("path to your image"));
    img.setImage(image);


    ^^ From memory, feel free to correct me @Savior
    --- Double Post Merged, May 13, 2016, Original Post Date: May 13, 2016 ---
    Also, you should join the developer Slack chat, you're likely to get a quicker answer.

    Slack
     
    Stopper Blocker likes this.
  4. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    Don't forget to add it as a <resource> in your manifest.
     
    Stopper Blocker likes this.
  5. Stopper Blocker

    Joined:
    Apr 19, 2016
    Messages:
    55
    Likes Received:
    17
    @Party, @proxi,

    Thanks guys!

    Also, that's true, I should join the Slack channel.
     
    proxi likes this.

Share This Page

Loading...