I am attempting to build a twitter client using Twitter4. I am storing the users tweets and info etc in a DefaultListModel in a Jlist. I want to add the users profile picture and to do this I am setting the Icon using a ListCellRenderer. My issue here is that I am only able to set the ListCellRenderer text and icon to one users information. I use a loop to pull down multiple tweets and add them to the model, but the renderer is only setting one tweet many times.
This is the code to retrieve a tweet
for (int i = 0; i < list.size(); i++) {
Status each = (Status) list.get(i);
UI.model.addElement("<html><body style='width: 450px;'>"
+ "@"
+ each.getUser().getScreenName()
+ " - "
+ each.getText() + "<html><br>");
UI.whatIsDisplayedList.setCellRenderer(new newsFeedRenderer(each)); }
And this is how I am setting the ListCellRenderer
JLabel pic = new JLabel();
try {
ImageIcon img = new ImageIcon(TwitterFunctions.eachTweetProfilePic(each.getUser()));
pic.setIcon(img);
setIcon(img);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setText( "@" + each.getUser().getScreenName() + " - " + each.getText());
What modifications would I have to make to enable the correct formatting of the tweets?
Thanks for the help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…