我想动态地将数据添加到包括图像的 JTable 中。这是我的代码:
主班
String image = matchedSlots.get(i).getImagePath();
String title = matchedSlots.get(i).getTitle();
String director = matchedSlots.get(i).getDirector();
int rating = matchedSlots.get(i).getRating();
int runTime = matchedSlots.get(i).getRunningTime();
searchResults.getColumnModel().getColumn(i).setCellRenderer(new ImageRender(image));
DefaultTableModel tm = (DefaultTableModel) searchResults.getModel();
tm.addRow(new Object[] {image,title,director,rating,runTime});
图像渲染器类
public class ImageRender extends DefaultTableCellRenderer{
ImageIcon icon = null;
public ImageRender(String iconName)
{
icon = new ImageIcon(getClass().getResource(iconName));
}
}
这不起作用。只有路径名显示在屏幕上。我怎样才能解决这个问题