clear the java buffer

Discussion in 'Java' started by Emmanuel Freund, Nov 24, 2004.

  1. I have a strange error:

    With this function:


    public static ImageIcon loadImageIcon(String file, String iconName) {
    return new ImageIcon(file+ '/' + iconName);
    }
    I first rename Image1.jpg to someImage.jpg and call this function with
    loadImageIcon(myFile,someImage.jpg).
    So Image1.jpg is loaded and paint (with some other functions of course).
    Then during my execution, I rename Image2.jpg to someImage.jpg and call
    loadImageIcon(myFile,someImage.jpg).
    Then the Image loaded is still Image1.jpg.

    Is that possible that Java remember that's the same function called with the
    same variables, and so don't reload the Image and instead take the Image
    from a buffer somewhere?
    And if it's the case, how can we clear the buffer so the Image2.jpg is
    reloaded?
    Thanks,
     
    Emmanuel Freund, Nov 24, 2004
    #1
    1. Advertisements

  2. Emmanuel Freund

    Ann Guest

    Try closing the file.
     
    Ann, Nov 24, 2004
    #2
    1. Advertisements

  3. I may have missed something, but I used an ImageIcon which takes one string
    and no file in its constructor... So I think all the openning-closing
    operations are done in this constructor to which I don't have access.
    So, how I close a file I haven't open ?
     
    Emmanuel Freund, Nov 24, 2004
    #3
  4. Andrew Thompson, Nov 24, 2004
    #4
  5. So?
    <http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/ImageIcon.html#ImageIcon(java.lang.String)>

    Which, if you look at the source of ..
    <http://www.physci.org/source.jsp?class=javax.swing.ImageIcon>
    You'll notice it calls..
    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#getImage(java.lang.String)>

    'caching'.

    Don't use ImageIcons if you don't want the image cached,
    load the bytes yourself and use ..
    <http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Toolkit.html#createImage(byte[])>

    HTH
     
    Andrew Thompson, Nov 24, 2004
    #5
  6. Thank you very much Andrew, that was the problem.
     
    Emmanuel Freund, Nov 24, 2004
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.