开发者

how can i insert a image in swing JList menu?

开发者 https://www.devze.com 2022-12-11 18:25 出处:网络
this is my code: URL imageUrl = status.getUser().getProfileImageURL(); ImageIcon tivitImage = new ImageIcon(imageUrl);

this is my code:

URL imageUrl = status.getUser().getProfileImageURL();
ImageIcon tivitImage = new ImageIcon(imageUrl);
listModel.addElement(tivitImage.getImage开发者_如何学JAVA());  // maybe this part is wrong 


listModel.addElement(tivitImage.getImage()); // maybe this part is wrong

Yes, thats the problem. Just add the Icon to the ListModel (not the image). JList supports a default renderer for Icons.


You could subclass JList or use your own ListCellRenderer, as it is shown in this article.

Another reading: http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JList.html, towards the end, a jlist with country flags is explained.

0

精彩评论

暂无评论...
验证码 换一张
取 消