Dynamically add images to JTable cells

后端 未结 2 708
灰色年华
灰色年华 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/

    0 讨论(0)
  • 2021-01-29 00:31

    By default JTable can render Images. You just need to override getColumnClass() in the TableModel and return Icon.class for 1st column.

    Look at Renderers and Editors for more details.

    0 讨论(0)
提交回复
热议问题