gpt4 book ai didi

java - 从结果列表构建 Java TableModel

转载 作者:行者123 更新时间:2023-12-01 18:51:55 26 4
gpt4 key购买 nike

您好,我在填充 TableModel 时遇到问题,我无法理解问题所在

这是我的方法

 private TableModel buildTableModel(List<Player> result) {
// build the columns
Vector<String> columnNames = new Vector<String>();
//int columnCount = metaData.getColumnCount();
//for (int column = 1; column <= columnCount; column++) {
// columnNames.add(metaData.getColumnName(column));
//}

columnNames.add("playerid");
columnNames.add("squeezePlay");
columnNames.add("weakShowdown");
columnNames.add("numberOfPlays");
columnNames.add("playsWithFriends");
columnNames.add("suspend");
columnNames.add("grade");


// data of the table
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while (result.iterator().hasNext()) {
Player player = result.iterator().next();

Vector<Object> vector = new Vector<Object>();

vector.add((Object) player.GetId());
vector.add((Object) player.GetSqueezePlay());
vector.add((Object) player.GetWeakShowdown());
vector.add((Object) player.GetNumberOfPlays());
vector.add((Object) player.GetPlaysWithFriends());
vector.add((Object) player.GetSuspended());
vector.add((Object) player.GetGrade());

data.add(vector);
}

return new DefaultTableModel(data, columnNames);

}

注意:无论有或没有Object转换,表格仍然无法工作..

请建议任何替代解决方案来填充 TableModel。

谢谢!!

最佳答案

每次调用 result.iterator() 时,您都会读取列表的开头。相反,使用这个:

for (Player player : result)

关于java - 从结果列表构建 Java TableModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15604736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com