我在扩展 JEditorPane 的 ListCellRenderer 中有此代码。编辑器窗格不显示图像,而是显示“损坏的图标”。它出什么问题了?
public class TweetCellRenderer extends JEditorPane implements ListCellRenderer {
public Component getListCellRendererComponent(
javax.swing.JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus
) {
setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 6));
StringBuffer sb = new StringBuffer();
setContentType("text/html");
sb.append("<html><body>");
sb.append("<img src='http://www.google.co.uk/images/firefox/video.png' />");
sb.append("</body></html>");
System.out.println(sb);
setText(sb.toString());
setBackground(isSelected ? SELECTED_BG : BG);
setForeground(isSelected ? SELECTED_FG : FG);
return this;
}
}