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:
String ruta = data.get(row).getPath();
BufferedImage scaled = null;
ImageIcon ic = null;
File file = new File(ruta);
BufferedImage image = ImageIO.read(file);
scaled = scale(image, 100, 60);
ic = cache.get(ruta);
return new JLabel(ic);
What more can I do to optimize the heap and memory? thanks!!!!!
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 )
Re: Render imageicon in Jtable (I need optimize!)