Results 1 to 2 of 2
  1. #1
    jviure is offline Member
    Join Date
    Jun 2012
    Posts
    2
    Rep Power
    0

    Default Render imageicon in Jtable (I need optimize!)

    Hello people! my name is Jordi, from Barcelona.

    I am working in a java project. I've one Jtable where the first column is a jlabel with an imageicon inside. The idea is that the user select from his computer photos and when he click Add, the images are added to the jtable. This works fine but I've the windows task monitor opened and I see the ram memory grows A LOT. From 50mb to 400mb adding 10photos of 3mb every one. I don't know how can I optimize that. I know that the jtable is rendering every time, so I have created a customized "cache" --> HashMap<String,ImageIcon> cache; Then in the getValueAt (of my Jtable's model) I've this:

    if(col==0){
    try {
    String ruta = data.get(row).getPath();
    BufferedImage scaled = null;
    ImageIcon ic = null;
    if(cache.get(ruta)==null){
    File file = new File(ruta);
    BufferedImage image = ImageIO.read(file);
    scaled = scale(image, 100, 60);
    cache.put(ruta,ic=new ImageIcon(scaled));
    image.flush();
    }
    else{
    ic = cache.get(ruta);
    }
    return new JLabel(ic);
    }
    catch(Exception exc){

    }
    return "";
    }
    else if(col==1){
    ...

    What more can I do to optimize the heap and memory? thanks!!!!!

    Jordi

    pd: the scale function I think it's not the problem, is fast, the quality is not important because the thumbnail is so small (scale function: scale | Copy Paste Code )

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

Similar Threads

  1. Replies: 9
    Last Post: 09-11-2011, 05:27 PM
  2. Best Way To Render
    By rp181 in forum Java 2D
    Replies: 1
    Last Post: 03-24-2011, 06:20 PM
  3. why is it so slow? need to optimize it?
    By skarosg3 in forum Advanced Java
    Replies: 15
    Last Post: 10-08-2010, 08:54 AM
  4. Optimize my Code please....
    By mindblaster in forum New To Java
    Replies: 5
    Last Post: 02-06-2010, 11:32 AM
  5. Loki Render 0.3
    By levent in forum Java Software
    Replies: 0
    Last Post: 07-26-2007, 08:31 PM

Posting Permissions

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