我正在构建一个 Twitter 客户端,我不想检索和显示全球趋势。到目前为止(在某种程度上感谢 Stack Overflow 的帮助)我可以检索趋势信息,从中提取必要的信息并将趋势发布到控制台。当我尝试将趋势添加到表格中时,我只能多次显示第一个趋势,而且我不确定我的行创建等哪里出了问题。
一双新鲜的眼睛将不胜感激!
谢谢
public static void WorldWideTrends() {
Trends WorldWideTrendsList;
try {
WorldWideTrendsList = getTrends();
UI.whatIsDisplayedList.removeAll();
UI.tweetModel = new DefaultTableModel(10, 1);
String trendsInfo = WorldWideTrendsList.toString();
System.out.println(trendsInfo);
Pattern p = Pattern.compile("(#.*?)\\'", Pattern.DOTALL);
Matcher matcher = p.matcher(trendsInfo);
while (matcher.find()) {
for (int i = 0; i < 10; i++) {
String output = matcher.group(0);
System.out.println(output);
UI.tweetModel.insertRow(1, new Object[] {});
UI.tweetModel.setValueAt(
"<html><body style='width: 400px;'><strong>"
+ output + "</strong><html><br>", i, 0);
}
}
} catch (TwitterException e) {
e.printStackTrace();
}
UI.whatIsDisplayedList.setModel(UI.tweetModel);
}