Results 1 to 6 of 6
  1. #1
    pinkette is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default Loading images from an Array

    Hello, i have an array for example

    Java Code:
    images [0][0] = "images1.gif";
    images [0][1] = "images2.gif";
    I want to set an Image Icon using the images array.
    Java Code:
    pictureimage[i].setIcon(new ImageIcon (images[0][1]));
    That isnt the right syntax so wondered if anyone knew.
    Many Thanks

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Well, considering that you don't have images in that array, but rather strings that seemingly represent filenames (without paths), no, that's not the correct syntax.

    What does the API docs for ImageIcon say? What possible constructors can you use?

  3. #3
    pinkette is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    So in that array, would i need to include filenames for it to work? Im new to java so sorry if its a really stupid question.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    filenames is what you already have. What are the possible constructors for ImageIcon? See the API docs.

    A filename is acceptable, but hopefully the cwd is correct (probably not as it almost never is what a "newbie" expects it to be). You might also want to explain exactly what you mean by "isnt the right syntax". Do you get a compiler message? post it (completely). Do you get an exception? post it (completely). Does something else happen? describe it (fully). I believe you should be getting the idea by now.
    Last edited by masijade; 04-15-2011 at 11:29 AM.

  5. #5
    pinkette is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    Would it be this one?

    ImageIcon(Image image)
    Creates an ImageIcon from an image object.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Quote Originally Posted by pinkette View Post
    Would it be this one?

    ImageIcon(Image image)
    Creates an ImageIcon from an image object.
    Only if you had images rather than strings seemingly representing filenames in that 2d array.

Similar Threads

  1. Replies: 1
    Last Post: 03-26-2010, 10:41 PM
  2. Loading large images in JavaME
    By b12 in forum Advanced Java
    Replies: 1
    Last Post: 04-01-2009, 11:02 AM
  3. Loading images in seperate packages?
    By Bibendum in forum New To Java
    Replies: 0
    Last Post: 03-02-2008, 10:43 PM
  4. Loading Images - Imp
    By Thulasiraman in forum Advanced Java
    Replies: 0
    Last Post: 01-28-2008, 09:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •