How to display multiple images

Discussion in 'Java' started by John Broadley, Sep 14, 2004.

  1. I am building a simple Java application. I have a list box in which I
    list a list of image files .jpg, and I want to create an area beside
    the listbox, where whenever the user click on an image in the list, I
    can display the image for him. I tried the ImageIcon class, and
    creating an instance and putting it in a JLabel, which is in a
    scrollable window. It works fine. But now, when I want to display a
    new image. Do I need to create all these objects again and agian. What
    if I have 100 images, will I end up with a huge number of objects
    creates my my program. Please note that the average size of the images
    is 500kb.

    I saw also a lot of talking about Toolkit related code, but I was not
    able to use such library in my Eclipse platform. Do I need to import
    anything to be able to use the Toolkit facilities like getting for
    example the screen resolution?


    Appreciate your help.
     
    John Broadley, Sep 14, 2004
    #1
    1. Advertising

  2. John Broadley

    Paul Lutus Guest

    John Broadley wrote:

    > I am building a simple Java application. I have a list box in which I
    > list a list of image files .jpg, and I want to create an area beside
    > the listbox, where whenever the user click on an image in the list, I
    > can display the image for him. I tried the ImageIcon class, and
    > creating an instance and putting it in a JLabel, which is in a
    > scrollable window. It works fine. But now, when I want to display a
    > new image. Do I need to create all these objects again and agian.


    What objects are those? Be specific.

    > What
    > if I have 100 images, will I end up with a huge number of objects
    > creates my my program.


    No, only one image is loaded at a time, if you design your program
    appropriately.

    > Please note that the average size of the images
    > is 500kb.


    My digital camera creates 3072x2048 size images, and when displayed in true
    color (3 bytes per pixel), that is over 18 megabytes per image when
    uncompressed and loaded into memory. But in my slideshow Java program I
    only have one image in memory at a time, so this is no problem.

    >
    > I saw also a lot of talking about Toolkit related code, but I was not
    > able to use such library in my Eclipse platform. Do I need to import
    > anything to be able to use the Toolkit facilities like getting for
    > example the screen resolution?


    When your user clicks a thumbnail, load the appropriate image. Arrange for
    this action to abandon the prior image, and the garbage collector will
    reclaim its memory.

    Do you want more specific information? Post more specific information. Post
    your code.

    --
    Paul Lutus
    http://www.arachnoid.com
     
    Paul Lutus, Sep 14, 2004
    #2
    1. Advertising

  3. On 13 Sep 2004 23:46:19 -0700, John Broadley wrote:

    > I am building a simple Java application. I have a list box in which I
    > list a list of image files .jpg, ...


    A better group for GUI related matters is described here..
    <http://www.physci.org/codes/javafaq.jsp#cljg>

    > I saw also a lot of talking about Toolkit related code,


    Make sure you steer clear of
    Toolkit.getImage() which states..
    "Since the mechanism required to facilitate this sharing
    of Image objects may continue to hold onto images that
    are no longer of use for an indefinite period of time,
    developers are encouraged to implement their own caching
    of images by using the createImage variant wherever available. "

    Caching is not good when you have a slideshow
    of 500Kb+ images.

    >...but I was not
    > able to use such library in my Eclipse platform.


    Eclipse is neither the problem nor the solution
    in this one. The problem is in your code.

    >..Do I need to import
    > anything to be able to use the Toolkit facilities


    Toolkit tk = Tookmit.getDefaultToolkit();

    > Appreciate your help.


    You're welcome.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Sep 14, 2004
    #3
  4. John Broadley

    ak Guest

    > I am building a simple Java application. I have a list box in which I
    > list a list of image files .jpg, and I want to create an area beside
    > the listbox, where whenever the user click on an image in the list, I
    > can display the image for him. I tried the ImageIcon class, and
    > creating an instance and putting it in a JLabel, which is in a
    > scrollable window. It works fine. But now, when I want to display a
    > new image. Do I need to create all these objects again and agian.

    no just call
    Image image = Toolkit.getDefaultToolkit.createImage();
    ImageIcon#setImage(image);

    --
    Andrei Kouznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
     
    ak, Sep 14, 2004
    #4
  5. John Broadley

    FISH Guest

    (John Broadley) wrote in message news:<>...
    > I am building a simple Java application. I have a list box in which I
    > list a list of image files .jpg, and I want to create an area beside
    > the listbox, where whenever the user click on an image in the list, I
    > can display the image for him. I tried the ImageIcon class, and
    > creating an instance and putting it in a JLabel, which is in a
    > scrollable window. It works fine. But now, when I want to display a
    > new image. Do I need to create all these objects again and agian. What
    > if I have 100 images, will I end up with a huge number of objects
    > creates my my program. Please note that the average size of the images
    > is 500kb.


    Possibly the cleanest solution (and the one with potentially the least
    resource overhead) is to make your own Icon implementation, which
    supports 'hot swapping' of images. The Icon interface is very straight
    forward, and you shouldn't have any problem rolling your own. As well
    as the Icon methods, add your own method which allows for the current
    image to change. Don't forget to inform the icon's container that it
    needs revalidating.


    > I saw also a lot of talking about Toolkit related code, but I was not
    > able to use such library in my Eclipse platform. Do I need to import
    > anything to be able to use the Toolkit facilities like getting for
    > example the screen resolution?


    java.awt.Toolkit ...? :)


    -FISH- ><>
     
    FISH, Sep 14, 2004
    #5
  6. John Broadley

    ak Guest

    > Possibly the cleanest solution (and the one with potentially the least
    > resource overhead) is to make your own Icon implementation, which
    > supports 'hot swapping' of images

    is it not already implemented in ImageIcon?

    --
    Andrei Kouznetsov
    http://uio.dev.java.net Unified I/O for Java
    http://reader.imagero.com Java image reader
     
    ak, Sep 14, 2004
    #6
  7. John Broadley

    FISH Guest

    "ak" <> wrote in message news:<ci6mi4$ka5$>...
    > > Possibly the cleanest solution (and the one with potentially the least
    > > resource overhead) is to make your own Icon implementation, which
    > > supports 'hot swapping' of images


    > is it not already implemented in ImageIcon?



    You're right! ImageIcon has a setImage() method, which I didn't even
    know existed. For some strange reason I'd got it into my head that
    ImageIcon's were immutable once created. Thanks for correcting me.


    -FISH- ><>
     
    FISH, Sep 15, 2004
    #7
  8. John Broadley

    mchitsaz

    Joined:
    Nov 8, 2008
    Messages:
    1
    same problem

    Dear John,

    I wanna to do the same stuff as you've done
    list a list of image files .jpg, and I want to create an area beside
    the listbox, where whenever the user click on an image in the list, I
    can display the image for him. I tried the ImageIcon class, and
    creating an instance and putting it in a JLabel, which is in a
    scrollable window.​

    Unfortunately Ii doesn't work!! Just for the first image the image shown in scrollpane, but after clicking in other image number, the image does not appear.

    My code is this:

    PlanarImage im=JAI.create("fileload", path);
    //decreasing size of image
    BufferedImage image = new BufferedImage((int) Math.round(512*scale),(int) Math.round(512*scale), BufferedImage.TYPE_INT_RGB);

    image.createGraphics().drawImage(im.getAsBufferedImage(), 0, 0,image.getWidth(), image.getHeight(), null);

    ImageIO.write(image, "PNG", new File(path));

    images = new ImageIcon(path);
    lable = new JLabel(images);

    jScrollPane3.getViewport().add(lable);​

    May you help me?

    Thanks.

    Mahsa
     
    mchitsaz, Nov 8, 2008
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZGF2aWQ=?=

    How to display multiple images in one browser window?

    =?Utf-8?B?ZGF2aWQ=?=, May 10, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    9,081
    Brock Allen
    May 10, 2005
  2. Knoppix User
    Replies:
    1
    Views:
    335
    Knoppix User
    Dec 31, 2003
  3. Steven Saunderson

    Fluid display for multiple images

    Steven Saunderson, Feb 16, 2007, in forum: HTML
    Replies:
    12
    Views:
    715
    dorayme
    Feb 20, 2007
  4. suresh.amritapuri

    PIL how to display multiple images side by side

    suresh.amritapuri, Jan 8, 2010, in forum: Python
    Replies:
    4
    Views:
    1,078
    Alf P. Steinbach
    Jan 11, 2010
  5. cp
    Replies:
    3
    Views:
    207
    Jason
    Dec 24, 2004
Loading...

Share This Page