I am trying to use JTable
for showing my personnel list with each picture dedicated to each person. I want to show these images in a JTable
cell. I achieved showing images from directory with custom cell renderer. This cell renderer returns the label which has icon via the method new ImageIcon()
. Every time scrolling happens in my JTable
, I guess this renderer works and creates new images from the directory. So this makes RAM explode and glitches in the images. I read all of the questions related to this problem, however I could not find an efficient way to solve it. An approach to this problem would be much appreciated.
My renderer looks like:
public class ImageCellRenderer extends DefaultTableCellRenderer{
JLabel lbl=new JLabel();
public Component getTableCellRendererComponent(defaultparameters){
ImageIcon imageIcon=new ImageIcon(getClass().getResource("path to directory"+table.getModel().getValueAt(row,column).toString+".jpg"));
"""
Some code to turn image icon to scaled version
"""
lbl.setIcon(imageIcon)
return lbl;
}
}