Dynamically add images to JTable cells

后端 未结 2 710
灰色年华
灰色年华 2021-01-28 23:49

I am dynamically adding data to a cell with the following code:

for(int i = 0; i < matchedSlots.size(); i++)
{  
  String title = matchedSlots.get(i).getTitle         


        
2条回答
  •  深忆病人
    2021-01-29 00:19

    ImageIcon image = new ImageIcon("image.gif");
    ...
    tm.addRow(new Object[] {image,title,director,rating,runTime});
    

    You may need to change your table model to account for the new column if you haven't already.

    This short article should help you with the image renderer: http://mdsaputra.wordpress.com/2011/06/13/swing-hack-show-image-in-jtable/

提交回复
热议问题